Skip to content

Instantly share code, notes, and snippets.

@clairechabas
Created July 31, 2019 15:40
Show Gist options
  • Save clairechabas/d71fbc2fbaeb2633820ecb0ceb0132b6 to your computer and use it in GitHub Desktop.
Save clairechabas/d71fbc2fbaeb2633820ecb0ceb0132b6 to your computer and use it in GitHub Desktop.
Sign-in action creator using Firebase Auth
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