1
0
forked from noxious/client

npm update, added email field

This commit is contained in:
2024-10-27 17:48:04 +01:00
parent 7db2ba322c
commit 446e049e6e
3 changed files with 29 additions and 24 deletions

View File

@ -40,6 +40,7 @@
<div class="flex flex-col gap-5 p-2 mb-8 relative">
<div class="w-full grid gap-3 relative">
<input class="input-field xs:min-w-[350px] min-w-64" id="username-register" v-model="username" type="text" name="username" placeholder="Username" required autofocus />
<input class="input-field xs:min-w-[350px] min-w-64" id="email-register" v-model="email" type="email" name="email" placeholder="Email" required />
<div class="relative">
<input class="input-field xs:min-w-[350px] min-w-64" id="password-register" v-model="password" :type="showPassword ? 'text' : 'password'" name="password" placeholder="Password" required />
<button type="button" @click.prevent="showPassword = !showPassword" :class="{ 'eye-open': showPassword }" class="bg-[url('/assets/icons/eye.svg')] p-0 absolute right-3 w-4 h-3 top-1/2 -translate-y-1/2 bg-no-repeat"></button>
@ -74,6 +75,7 @@ import { useCookies } from '@vueuse/integrations/useCookies'
const gameStore = useGameStore()
const username = ref('')
const password = ref('')
const email = ref('')
const switchForm = ref('login')
const loginError = ref('')
const showPassword = ref(false)
@ -108,13 +110,13 @@ async function loginFunc() {
async function registerFunc() {
// check if username and password are valid
if (username.value === '' || password.value === '') {
loginError.value = 'Please enter a valid username and password'
if (username.value === '' || email.value === '' || password.value === '') {
loginError.value = 'Please enter a valid username, email, and password'
return
}
// send register event to server
const response = await register(username.value, password.value)
const response = await register(username.value, email.value, password.value)
if (response.success === undefined) {
loginError.value = response.error

View File

@ -2,9 +2,9 @@ import axios from 'axios'
import config from '@/config'
import { useCookies } from '@vueuse/integrations/useCookies'
export async function register(username: string, password: string) {
export async function register(username: string, email: string, password: string) {
try {
const response = await axios.post(`${config.server_endpoint}/register`, { username, password })
const response = await axios.post(`${config.server_endpoint}/register`, { username, email, password })
useCookies().set('token', response.data.token as string)
return { success: true, token: response.data.token }
} catch (error: any) {