()
| 75 | |
| 76 | // ✅ Google Login |
| 77 | export const googleLogin = async () => { |
| 78 | try { |
| 79 | const userCredential = await signInWithPopup(auth, googleProvider); |
| 80 | if (!userCredential.user.email) { |
| 81 | throw new Error("Google user does not have an email."); |
| 82 | } |
| 83 | |
| 84 | // Check if user exists in the database |
| 85 | const isExist = await getUserByEmail(userCredential.user.email); |
| 86 | if (!isExist) { |
| 87 | await addUser({ |
| 88 | uid: userCredential.user.uid, |
| 89 | name: userCredential.user.displayName || "Google User", |
| 90 | email: userCredential.user.email, |
| 91 | role: "user", |
| 92 | }); |
| 93 | } |
| 94 | |
| 95 | return userCredential; |
| 96 | } catch (error) { |
| 97 | const errorCode = (error as { code: string }).code; |
| 98 | throw new Error(errorCode); |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | // ✅ Logout |
| 103 | export const logout = async () => { |
no test coverage detected