aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/actions/firebaseAuth.js79
-rw-r--r--src/reducers/firebaseAuth.js20
2 files changed, 50 insertions, 49 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;
diff --git a/src/reducers/firebaseAuth.js b/src/reducers/firebaseAuth.js
index ced6c1c..37b5cf6 100644
--- a/src/reducers/firebaseAuth.js
+++ b/src/reducers/firebaseAuth.js
@@ -10,8 +10,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
import {
AUTH_SUCCESS,
- AUTH_SIGN_OUT,
- UPDATE_ADMIN
+ AUTH_FAIL,
+ AUTH_SIGN_OUT
}
from '../actions/firebaseAuth.js';
@@ -19,7 +19,14 @@ const firebaseAuth = (state = {signedIn: false, uid: "", userEmail: ""}, action)
switch (action.type) {
case AUTH_SUCCESS:
return {
- ...state,
+ signedIn: action.payload,
+ uid: action.uid,
+ userEmail: action.userEmail
+ };
+ break;
+
+ case AUTH_FAIL:
+ return {
signedIn: action.payload,
uid: action.uid,
userEmail: action.userEmail
@@ -28,9 +35,10 @@ const firebaseAuth = (state = {signedIn: false, uid: "", userEmail: ""}, action)
case AUTH_SIGN_OUT:
return {
- ...state,
- signedIn: action.payload
- }
+ signedIn: action.payload,
+ uid: action.uid,
+ userEmail: action.userEmail
+ };
break;
default: