MCPcopy Create free account
hub / github.com/Hazrat-Ali9/Problem-Solving-Frontend / googleLogin

Function googleLogin

lib/firebase/authService.ts:77–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75
76// ✅ Google Login
77export 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
103export const logout = async () => {

Callers 1

loginFunction · 0.90

Calls 2

getUserByEmailFunction · 0.90
addUserFunction · 0.90

Tested by

no test coverage detected