MCPcopy Create free account
hub / github.com/WardAnalytics/WardGraph / login

Function login

src/services/auth/auth.services.ts:54–81  ·  view source on GitHub ↗
(
  email: string,
  password: string,
  onSuccess: (userID: string) => void,
  onError: (error: any) => void,
)

Source from the content-addressed store, hash-verified

52 * @param onError - callback function to be executed on login error
53 */
54const login = async (
55 email: string,
56 password: string,
57 onSuccess: (userID: string) => void,
58 onError: (error: any) => void,
59) => {
60 await signInWithEmailAndPassword(auth, email, password)
61 .then((userCredential) => {
62 const user = userCredential.user;
63
64 // Check if user email is verified
65 if (user && !user.emailVerified) {
66 onError(AuthApiErrorCodes.EMAIL_VERIFICATION_REQUIRED);
67 return;
68 }
69
70 localStorage.setItem("user", JSON.stringify(user));
71
72 // Saves user in the firestore database
73 // This function is called here and not in signUp to save already existing users in production
74 createUserInDatabase(user).then(() => {
75 onSuccess(user.uid);
76 });
77 })
78 .catch((error) => {
79 onError(error);
80 });
81};
82
83/**
84 * Logout the current user

Callers

nothing calls this directly

Calls 1

createUserInDatabaseFunction · 0.90

Tested by

no test coverage detected