From f0815df6642642db3e5063b6800d2ed0f681754c Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Thu, 26 Jul 2018 00:31:25 -0400 Subject: Created basic login system using firebase and redux. --- src/actions/firebase.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/actions/firebase.js (limited to 'src/actions') diff --git a/src/actions/firebase.js b/src/actions/firebase.js new file mode 100644 index 0000000..e13ab10 --- /dev/null +++ b/src/actions/firebase.js @@ -0,0 +1,30 @@ +import { firebase } from '../firebase.js'; + +export const AUTH_FAIL = 'AUTH_FAIL'; +export const AUTH_SUCCESS = 'AUTH_SUCCESS'; + +const auth = firebase.auth(); + +export const signIn = (_email, _password) => (dispatch) => { + auth.signInWithEmailAndPassword(_email, _password).then((user) => { + dispatch(authSuccess(user.email)); + }) + .catch((error) => { + dispatch(authFail(error.code)); + }); + +} + +export const authFail = (errorCode) => { + return { + type: AUTH_FAIL, + payload: false + } +} + +export const authSuccess = (email) => { + return { + type: AUTH_SUCCESS, + payload: true + } +} -- cgit v1.2.3-70-g09d2