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.js76
1 files changed, 68 insertions, 8 deletions
diff --git a/src/actions/firebase.js b/src/actions/firebase.js
index e13ab10..85ebe20 100644
--- a/src/actions/firebase.js
+++ b/src/actions/firebase.js
@@ -1,13 +1,26 @@
-import { firebase } from '../firebase.js';
+import { firebase, firestore } from '../firebase.js';
-export const AUTH_FAIL = 'AUTH_FAIL';
-export const AUTH_SUCCESS = 'AUTH_SUCCESS';
+//Start Firbase Auth
+export const AUTH_FAIL = 'AUTH_FAIL';
+export const AUTH_SUCCESS = 'AUTH_SUCCESS';
+export const AUTH_SIGN_OUT = 'AUTH_SIGN_OUT';
const auth = firebase.auth();
export const signIn = (_email, _password) => (dispatch) => {
- auth.signInWithEmailAndPassword(_email, _password).then((user) => {
- dispatch(authSuccess(user.email));
+ 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));
+ dispatch(getHours())
})
.catch((error) => {
dispatch(authFail(error.code));
@@ -18,13 +31,60 @@ export const signIn = (_email, _password) => (dispatch) => {
export const authFail = (errorCode) => {
return {
type: AUTH_FAIL,
- payload: false
+ payload: false,
+ code: errorCode,
+ uid: null
}
}
-export const authSuccess = (email) => {
+export const authSuccess = (_user) => {
+ alert('authSuccess');
return {
type: AUTH_SUCCESS,
- payload: true
+ payload: true,
+ code: "Success",
+ uid: _user.uid
}
}
+
+export const signOut = () => (dispatch) => {
+ auth.signOut().then(() => {
+ dispatch(authSignOut());
+ });
+}
+
+export const authSignOut = () => {
+ return {
+ type: AUTH_SIGN_OUT,
+ payload: false,
+ code: "Signed Out User",
+ uid: null
+ }
+}
+//End Firebase Auth
+
+//Start Firebase Firestore
+export const GET_HOURS = 'GET_HOURS';
+export const UPDATE_HOURS = 'UPDATE_HOURS'
+
+export const getHours = () => (dispatch, getState) => {
+ const currentState = getState().firebase;
+ alert('ran');
+ if(currentState.initialized) {
+ var docRef = firestore.collection('users').doc(currentState.uid);
+ docRef.onSnapshot((doc) => {
+ dispatch(updateHours(doc.data().hours));
+ });
+ }
+
+
+}
+
+export const updateHours = (hours) => {
+ return {
+ type: 'UPDATE_HOURS',
+ payload: hours
+ }
+}
+
+//End Firebase Firestore