diff options
author | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-08-04 23:50:16 -0400 |
---|---|---|
committer | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-08-04 23:50:16 -0400 |
commit | dd18707b172db1cdc5a69a0a39b5fff3c5edc781 (patch) | |
tree | 73adbdff1a620573d3d6668bf617a1055e85a71e /src/actions/firebaseAuth.js | |
parent | 7a084f47ed17181af72629770cda3429af7656f7 (diff) |
Formatted the firebaseAuth reducers and actions to be more organized.
Diffstat (limited to 'src/actions/firebaseAuth.js')
-rw-r--r-- | src/actions/firebaseAuth.js | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/src/actions/firebaseAuth.js b/src/actions/firebaseAuth.js index c1bcd8a..720a172 100644 --- a/src/actions/firebaseAuth.js +++ b/src/actions/firebaseAuth.js @@ -1,17 +1,47 @@ import { auth } from '../firebase.js'; export const AUTH_SUCCESS = 'AUTH_SUCCESS'; -export const UPDATE_DIVISON = 'UPDATE_DIVISON'; +export const AUTH_FAIL = 'AUTH_FAIL'; export const AUTH_SIGN_OUT = 'AUTH_SIGN_OUT'; export const UPDATE_ADMIN = 'UPDATE_ADMIN'; +export const authFail = (errorCode) => { + alert(errorCode); + return { + type: AUTH_FAIL, + payload: false, + uid: "", + userEmail: "" + } +} + +export const authSuccess = (_user) => { + alert('Success. Checkout the other pages to see what you can do!'); + return { + type: AUTH_SUCCESS, + payload: true, + uid: _user.uid, + userEmail: _user.email + } +} + +export const authSignOut = () => { + return { + type: AUTH_SIGN_OUT, + payload: false, + uid: "", + userEmail: "" + } +} + +//Middleware to dispatches, normally triggered by user. + export const createAccount = (_email, _password, divison) => (dispatch) => { auth.createUserWithEmailAndPassword(_email, _password).then(() => { dispatch(signIn(_email, _password, divison)); }) .catch((error) => { - // Handle Errors here. - alert(error.code + ": " + error.message); + alert(error.code + ": " + error.message); }); } @@ -28,24 +58,20 @@ export const signIn = (_email, _password, divison) => (dispatch) => { var providerData = user.providerData; */ dispatch(authSuccess(user)); - if(divison) { - dispatch(setUserData(divison)); - } + if(divison) { dispatch(setUserData(divison)); } dispatch(fetchDivison()); dispatch(snapshotHours()) dispatch(snapshotRegisteredCompetitions()); //Admin controls if( user.uid === 'rxKROQAukzchWuueDLwA9c0YmsT2' || //Lucy Wood user.uid === 'sAVjlnSAETaP5VtTKGhfBKHKeQF2' //Michael Foiani - ) - { + ) { dispatch(adminListener()); } }) .catch((error) => { dispatch(authFail(error.code)); }); - } export const signOut = () => (dispatch) => { @@ -54,40 +80,7 @@ export const signOut = () => (dispatch) => { }); } -export const authSignOut = () => { - return { - type: AUTH_SIGN_OUT, - payload: false, - code: "Signed Out User", - uid: "", - userEmail: "", - isAdmin: false, - requests: [], - compList: [] - } -} - -export const authFail = (errorCode) => { - alert(errorCode); - return { - type: AUTH_FAIL, - payload: false, - uid: null - } -} - -export const authSuccess = (_user) => { - alert('Success. Checkout the other pages to see what you can do!'); - return { - type: AUTH_SUCCESS, - payload: true, - uid: _user.uid, - userEmail: _user.email - } -} - -//End firebase auth - +//other export const setUserData = (_divison) => (dispatch, getState) => { const uid = getState().firebase.uid; |