@@ -6,114 +6,114 @@ import {
66 GithubAuthProvider ,
77 signInWithEmailAndPassword ,
88 createUserWithEmailAndPassword ,
9- } from " firebase/auth" ;
10- import { mdiGoogle , mdiGithub , mdiEmail } from " @mdi/js" ;
9+ } from ' firebase/auth'
10+ import { mdiGoogle , mdiGithub , mdiEmail } from ' @mdi/js'
1111
1212const props = withDefaults (
1313 defineProps <{
14- to? : string ;
14+ to? : string
1515 }>(),
16- { to: " / " },
17- );
16+ { to: ' / ' },
17+ )
1818
19- const router = useRouter ();
20- const authStore = useAuthStore ();
21- const notificationsStore = useNotificationsStore ();
22- const appStore = useAppStore ();
19+ const router = useRouter ()
20+ const authStore = useAuthStore ()
21+ const notificationsStore = useNotificationsStore ()
22+ const appStore = useAppStore ()
2323
24- const loading = ref (false );
25- const showEmailForm = ref (false );
26- const isSignUp = ref (false );
27- const email = ref (" " );
28- const password = ref (" " );
29- const emailError = ref (" " );
24+ const loading = ref (false )
25+ const showEmailForm = ref (false )
26+ const isSignUp = ref (false )
27+ const email = ref (' ' )
28+ const password = ref (' ' )
29+ const emailError = ref (' ' )
3030
3131async function signInWithGoogle() {
32- loading .value = true ;
32+ loading .value = true
3333 try {
34- const auth = getAuth ();
35- const result = await signInWithPopup (auth , new GoogleAuthProvider ());
36- onSuccess (result .user );
34+ const auth = getAuth ()
35+ const result = await signInWithPopup (auth , new GoogleAuthProvider ())
36+ onSuccess (result .user )
3737 } catch (error : unknown ) {
38- handleError (error , true );
38+ handleError (error , true )
3939 } finally {
40- loading .value = false ;
40+ loading .value = false
4141 }
4242}
4343
4444async function signInWithGithub() {
45- loading .value = true ;
45+ loading .value = true
4646 try {
47- const auth = getAuth ();
48- const result = await signInWithPopup (auth , new GithubAuthProvider ());
49- onSuccess (result .user );
47+ const auth = getAuth ()
48+ const result = await signInWithPopup (auth , new GithubAuthProvider ())
49+ onSuccess (result .user )
5050 } catch (error : unknown ) {
51- handleError (error , true );
51+ handleError (error , true )
5252 } finally {
53- loading .value = false ;
53+ loading .value = false
5454 }
5555}
5656
5757async function submitEmail() {
58- emailError .value = " " ;
59- loading .value = true ;
58+ emailError .value = ' '
59+ loading .value = true
6060 try {
61- const auth = getAuth ();
62- let result;
61+ const auth = getAuth ()
62+ let result
6363 if (isSignUp .value ) {
6464 result = await createUserWithEmailAndPassword (
6565 auth ,
6666 email .value ,
6767 password .value ,
68- );
68+ )
6969 } else {
7070 result = await signInWithEmailAndPassword (
7171 auth ,
7272 email .value ,
7373 password .value ,
74- );
74+ )
7575 }
76- onSuccess (result .user );
76+ onSuccess (result .user )
7777 } catch (error : unknown ) {
78- handleError (error );
78+ handleError (error )
7979 } finally {
80- loading .value = false ;
80+ loading .value = false
8181 }
8282}
8383
8484function onSuccess(user : unknown ) {
8585 notificationsStore .addNotification ({
86- message: " Login successful!" ,
87- type: " success" ,
88- });
89- authStore .onAuthStateChanged (user );
90- router .push ({ path: props .to });
86+ message: ' Login successful!' ,
87+ type: ' success' ,
88+ })
89+ authStore .onAuthStateChanged (user )
90+ router .push ({ path: props .to })
9191}
9292
9393function handleError(error : unknown , isSocial = false ) {
94- const firebaseError = error as { code? : string ; message? : string };
95- const code = firebaseError .code || " " ;
96- let message = " " ;
97- if (code === " auth/user-not-found" || code === " auth/invalid-credential" ) {
98- message = " Invalid email or password" ;
99- } else if (code === " auth/email-already-in-use" ) {
100- message = " An account with this email already exists" ;
101- } else if (code === " auth/weak-password" ) {
102- message = " Password must be at least 6 characters" ;
94+ const firebaseError = error as { code? : string ; message? : string }
95+ const code = firebaseError .code || ' '
96+ let message = ' '
97+ if (code === ' auth/user-not-found' || code === ' auth/invalid-credential' ) {
98+ message = ' Invalid email or password'
99+ } else if (code === ' auth/email-already-in-use' ) {
100+ message = ' An account with this email already exists'
101+ } else if (code === ' auth/weak-password' ) {
102+ message = ' Password must be at least 6 characters'
103103 } else if (
104- code === " auth/popup-closed-by-user" ||
105- code === " auth/cancelled-popup-request"
104+ code === ' auth/popup-closed-by-user' ||
105+ code === ' auth/cancelled-popup-request'
106106 ) {
107107 // User closed the popup, no error to show
108- return ;
108+ return
109109 } else {
110- message = firebaseError .message || " An error occurred" ;
110+ message = firebaseError .message || ' An error occurred'
111111 }
112112
113113 if (isSocial ) {
114- notificationsStore .addNotification ({ message , type: " error" });
114+ notificationsStore .addNotification ({ message , type: ' error' })
115115 } else {
116- emailError .value = message ;
116+ emailError .value = message
117117 }
118118}
119119 </script >
@@ -190,7 +190,7 @@ function handleError(error: unknown, isSocial = false) {
190190 type =" submit"
191191 :loading =" loading"
192192 >
193- {{ isSignUp ? " Sign Up" : " Sign In" }}
193+ {{ isSignUp ? ' Sign Up' : ' Sign In' }}
194194 </v-btn >
195195 <v-btn
196196 block
@@ -200,7 +200,7 @@ function handleError(error: unknown, isSocial = false) {
200200 @click =" isSignUp = !isSignUp"
201201 >
202202 {{
203- isSignUp ? " Already have an account? Sign In" : " No account? Sign Up"
203+ isSignUp ? ' Already have an account? Sign In' : ' No account? Sign Up'
204204 }}
205205 </v-btn >
206206 </v-form >
0 commit comments