Created
July 31, 2019 15:40
-
-
Save clairechabas/d71fbc2fbaeb2633820ecb0ceb0132b6 to your computer and use it in GitHub Desktop.
Sign-in action creator using Firebase Auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SIGNIN_SUCCESS, SIGNIN_ERROR } from "./actionTypes"; | |
import firebase from "../../services/firebase"; | |
// Signing in with Firebase | |
export const signin = (email, password, callback) => async dispatch => { | |
try { | |
firebase | |
.auth() | |
.signInWithEmailAndPassword(email, password) | |
.then(() => { | |
dispatch({ type: SIGNIN_SUCCESS }); | |
callback(); | |
}) | |
.catch(() => { | |
dispatch({ | |
type: SIGNIN_ERROR, | |
payload: "Invalid login credentials" | |
}); | |
}); | |
} catch (err) { | |
dispatch({ type: SIGNIN_ERROR, payload: "Invalid login credentials" }); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment