diff --git a/frontend/composables/user.ts b/frontend/composables/user.ts index 26bd362..4a49417 100644 --- a/frontend/composables/user.ts +++ b/frontend/composables/user.ts @@ -15,10 +15,15 @@ const userLogin = async (email: String, password: String) => { const user = userSchema.safeParse({ email, password }) - if (!user.success) return user.error.format() + if (!user.success) return user.error.flatten().fieldErrors await useCustomFetch('/sanctum/csrf-cookie') - await useCustomFetch('/login', { method: 'POST', body: user.data }) + const { error } = await useCustomFetch('/login', { + method: 'POST', + body: user.data, + }) + + if (error) return { user: 'Invalid User' } await getUser() } @@ -35,7 +40,12 @@ const userSignup = async (data: unknown) => { if (!newUser.success) return newUser.error.format() - await useCustomFetch('/register', { method: 'POST', body: newUser.data }) + const { error } = await useCustomFetch('/register', { + method: 'POST', + body: newUser.data, + }) + + if (error) return error await getUser() } diff --git a/frontend/pages/login/index.vue b/frontend/pages/login/index.vue index baf28b2..08d358f 100644 --- a/frontend/pages/login/index.vue +++ b/frontend/pages/login/index.vue @@ -1,101 +1,140 @@ - - - - Name - - - - Email - - - {{ errors.email }} - - - Password - - - {{ errors.password }} - - - - Password Confirmation - - - - - {{ errors.user }} - - - - - {{ isSignUp ? 'Sign up' : 'Sign in' }} - - - - {{ - isSignUp - ? 'Already have an account? Sign in' - : 'No account? Sign up' - }} - - - + + + + Name + + + + Email + + + {{ errors.email }} + + + Password + + + {{ errors.password }} + + + + Password Confirmation + + + + + {{ errors.user }} + + + + + {{ isSignUp ? 'Sign up' : 'Sign in' }} + + + + {{ + isSignUp + ? 'Already have an account? Sign in' + : 'No account? Sign up' + }} + + +