@@ -12,8 +12,10 @@ import {
1212 doc ,
1313 getDoc ,
1414 getDocs ,
15+ query ,
1516 setDoc ,
1617 updateDoc ,
18+ where ,
1719} from "firebase/firestore" ;
1820
1921interface UserTypeforSignup {
@@ -69,25 +71,24 @@ const updateUserData = async (key: string, value: string | number) => {
6971
7072const signUpWithCredential = async ( user : UserTypeforSignup & TUser ) => {
7173 const { email, password, ...rest } = user ;
72- await createUserWithEmailAndPassword ( auth , email , password )
73- . then ( ( credential ) => {
74+ await createUserWithEmailAndPassword ( auth , email , password ) . then (
75+ ( credential ) => {
7476 setDoc ( doc ( db , "users" , credential . user . uid ) , {
7577 ...rest ,
78+ email : email ,
7679 imgUrl : "" ,
7780 sizeType : null ,
7881 sneakerSize : 0 ,
7982 } ) ;
80- } )
81- . catch ( ( e ) => alert ( e ) ) ;
83+ }
84+ ) ;
8285} ;
8386
8487const signInWithCredential = async ( user : {
8588 email : string ;
8689 password : string ;
8790} ) => {
88- await signInWithEmailAndPassword ( auth , user . email , user . password )
89- . then ( )
90- . catch ( ( e ) => alert ( e . message ) ) ;
91+ await signInWithEmailAndPassword ( auth , user . email , user . password ) ;
9192} ;
9293
9394const signInWithGoogle = async ( ) => {
@@ -96,6 +97,7 @@ const signInWithGoogle = async () => {
9697 const isNew = await signInWithPopup ( auth , provider )
9798 . then ( ( credential ) => {
9899 setDoc ( doc ( db , "users" , credential . user . uid ) , {
100+ email : credential . user . email ,
99101 username : credential . user . displayName ,
100102 gender : null ,
101103 birthDate : "" ,
@@ -120,11 +122,20 @@ const logOut = async () => {
120122 . catch ( ( e ) => alert ( e . message ) ) ;
121123} ;
122124
125+ const availableAccount = async ( email : string ) => {
126+ const docRef = collection ( db , "users" ) ;
127+ const q = query ( docRef , where ( "email" , "==" , email ) ) ;
128+ const querySnapshot = await getDocs ( q ) ;
129+
130+ return querySnapshot . empty ;
131+ } ;
132+
123133export {
124134 getUserData ,
125135 updateUserData ,
126136 signUpWithCredential ,
127137 signInWithCredential ,
128138 signInWithGoogle ,
129139 logOut ,
140+ availableAccount ,
130141} ;
0 commit comments