77 signInWithEmailAndPassword ,
88 createUserWithEmailAndPassword ,
99 sendPasswordResetEmail ,
10+ updateProfile ,
11+ deleteUser ,
1012} from ' firebase/auth'
1113import { mdiGoogle , mdiGithub , mdiEmail } from ' @mdi/js'
1214import type { User as FirebaseUser } from ' firebase/auth'
@@ -29,6 +31,7 @@ const showEmailForm = ref(false)
2931const isSignUp = ref (false )
3032const showForgotPassword = ref (false )
3133const resetEmailSent = ref (false )
34+ const name = ref (' ' )
3235const email = ref (' ' )
3336const password = ref (' ' )
3437const generalError = ref (' ' )
@@ -71,6 +74,10 @@ function validateEmail(): boolean {
7174function validateLoginForm(): boolean {
7275 clearErrors ()
7376 let valid = true
77+ if (isSignUp .value && ! name .value .trim ()) {
78+ errorMessages .value .add (' name' , ' Please provide your name' )
79+ valid = false
80+ }
7481 if (! email .value .trim ()) {
7582 errorMessages .value .add (' email' , ' Please provide an email address' )
7683 valid = false
@@ -126,6 +133,14 @@ async function submitEmail() {
126133 email .value .trim (),
127134 password .value ,
128135 )
136+ try {
137+ await updateProfile (result .user , {
138+ displayName: name .value .trim (),
139+ })
140+ } catch (error ) {
141+ await deleteUser (result .user )
142+ throw error
143+ }
129144 } else {
130145 result = await signInWithEmailAndPassword (
131146 auth ,
@@ -167,6 +182,11 @@ function backToSignIn() {
167182 showForgotPassword .value = false
168183}
169184
185+ function toggleAuthMode() {
186+ clearErrors ()
187+ isSignUp .value = ! isSignUp .value
188+ }
189+
170190function onSuccess(user : FirebaseUser , method : LoginMethod ) {
171191 try {
172192 localStorage .setItem (LAST_LOGIN_METHOD_KEY , method )
@@ -405,6 +425,20 @@ function getGeneralErrorMessage(
405425 class =" mt-4"
406426 @submit.prevent =" submitEmail"
407427 >
428+ <v-text-field
429+ v-if =" isSignUp"
430+ v-model =" name"
431+ label =" Name"
432+ color =" primary"
433+ type =" text"
434+ variant =" outlined"
435+ density =" comfortable"
436+ class =" mb-2"
437+ persistent-hint
438+ hint =" e.g John Doe"
439+ :error =" errorMessages.has('name')"
440+ :error-messages =" errorMessages.get('name')"
441+ />
408442 <v-text-field
409443 v-model =" email"
410444 label =" Email Address"
@@ -455,7 +489,7 @@ function getGeneralErrorMessage(
455489 size =" small"
456490 color =" primary"
457491 class =" mt-2"
458- @click =" isSignUp = !isSignUp "
492+ @click =" toggleAuthMode "
459493 >
460494 {{
461495 isSignUp ? 'Already have an account? Sign In' : 'No account? Sign Up'
0 commit comments