aboutsummaryrefslogtreecommitdiff
path: root/src/actions/firebase.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions/firebase.js')
-rw-r--r--src/actions/firebase.js135
1 files changed, 1 insertions, 134 deletions
diff --git a/src/actions/firebase.js b/src/actions/firebase.js
index db6edb0..6dca3d2 100644
--- a/src/actions/firebase.js
+++ b/src/actions/firebase.js
@@ -1,4 +1,4 @@
-import { firebase, firestore } from '../firebase.js';
+import { firestore, auth } from '../firebase.js';
//Start Firbase Auth
export const AUTH_FAIL = 'AUTH_FAIL';
@@ -13,141 +13,8 @@ export const ADMIN_CONTROLS = 'ADMIN_CONTROLS';
export const UPDATE_ADMIN = 'UPDATE_ADMIN';
export const SET_USER_DATA = 'SET_USER_DATA';
-const auth = firebase.auth();
-export const createAccount = (_email, _password, divison) => (dispatch) => {
- firebase.auth().createUserWithEmailAndPassword(_email, _password).then(() => {
- dispatch(signIn(_email, _password, divison));
- })
- .catch((error) => {
- // Handle Errors here.
- alert(error.code + ": " + error.message);
- });
-}
-
-export const signIn = (_email, _password, divison) => (dispatch) => {
- auth.signInWithEmailAndPassword(_email, _password).then(() => {
- var user = auth.currentUser;
- /* User is signed in.
- var displayName = user.displayName;
- var email = user.email;
- var emailVerified = user.emailVerified;
- var photoURL = user.photoURL;
- var isAnonymous = user.isAnonymous;
- var uid = user.uid;
- var providerData = user.providerData;
- */
- dispatch(authSuccess(user));
- 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 setUserData = (_divison) => (dispatch, getState) => {
- const uid = getState().firebase.uid;
- var docRef = firestore.collection('users').doc(uid);
- docRef.set({
- hours: 0,
- divison: _divison
- }).catch((error) => {
- console.log(error);
- })
-}
-
-export const adminListener = () => (dispatch, getState) => {
- document.onkeyup = function(e) {
- if(e.altKey && e.which == 65) {
- var docRef = firestore.collection('keys').doc('adminKey');
- docRef.get().then((doc) => {
- if(prompt('Enter admin password') == doc.data().password) {
- dispatch(adminControls());
- }
- });
- }
- }
-}
-
-export const authFail = (errorCode) => {
- alert(errorCode);
- return {
- type: AUTH_FAIL,
- payload: false,
- uid: null
- }
-}
-
-export const authSuccess = (_user) => {
- alert('Sign In Success');
- return {
- type: AUTH_SUCCESS,
- payload: true,
- uid: _user.uid,
- userEmail: _user.email
- }
-}
-
-export const fetchDivison = () => (dispatch, getState) => {
- const uid = getState().firebase.uid;
- var docRef = firestore.collection('users').doc(uid);
-
- docRef.get().then((doc) => {
- dispatch(updateDivison(doc.data().divison));
- });
-}
-
-export const updateDivison = (divison) => {
- return {
- type: UPDATE_DIVISON,
- payload: divison
- }
-}
-
-export const adminControls = () => (dispatch) => {
- dispatch(updateAdmin());
- dispatch(snapshotAdminRequests());
- dispatch(snapshotAdminCompList());
-}
-
-export const updateAdmin = () => {
- return {
- type: UPDATE_ADMIN,
- payload: true
- }
-}
-export const signOut = () => (dispatch) => {
- auth.signOut().then(() => {
- dispatch(authSignOut());
- });
-}
-
-export const authSignOut = () => {
- return {
- type: AUTH_SIGN_OUT,
- payload: false,
- code: "Signed Out User",
- uid: "",
- userEmail: "",
- isAdmin: false,
- requests: [],
- compList: []
- }
-}
//End Firebase Auth
//Start Firebase Firestore