Replaced remaining parts of app to use Redux.
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
import { all, call, put, takeLatest } from "redux-saga/effects";
|
||||
import { auth, getCurrentUser } from "../../firebase/firebase.utils";
|
||||
import {
|
||||
signInFailure,
|
||||
signInSuccess,
|
||||
signOutFailure,
|
||||
signOutSuccess,
|
||||
unauthorizedUser
|
||||
} from "./user.actions";
|
||||
import { signInFailure, signInSuccess, signOutFailure, signOutSuccess, unauthorizedUser } from "./user.actions";
|
||||
import UserActionTypes from "./user.types";
|
||||
|
||||
// export function* getSnapshotFromUserAuth(userAuth) {
|
||||
@@ -23,7 +17,7 @@ export function* signInWithEmail({ payload: { email, password } }) {
|
||||
const { user } = yield auth.signInWithEmailAndPassword(email, password);
|
||||
yield put(
|
||||
signInSuccess({
|
||||
id: user.uid,
|
||||
uid: user.uid,
|
||||
email: user.email,
|
||||
displayName: user.displayName,
|
||||
authorized: true
|
||||
@@ -45,9 +39,13 @@ export function* isUserAuthenticated() {
|
||||
yield put(unauthorizedUser());
|
||||
return;
|
||||
}
|
||||
let token = yield user.getIdToken();
|
||||
localStorage.setItem("token", token);
|
||||
window.sessionStorage.setItem(`lastTokenRefreshTime`, new Date());
|
||||
|
||||
yield put(
|
||||
signInSuccess({
|
||||
id: user.uid,
|
||||
uid: user.uid,
|
||||
email: user.email,
|
||||
displayName: user.displayName,
|
||||
authorized: true
|
||||
@@ -66,6 +64,7 @@ export function* signOutStart() {
|
||||
try {
|
||||
yield auth.signOut();
|
||||
yield put(signOutSuccess());
|
||||
localStorage.removeItem("token");
|
||||
} catch (error) {
|
||||
yield put(signOutFailure(error.message));
|
||||
}
|
||||
@@ -75,12 +74,13 @@ export function* onSignOutStart() {
|
||||
yield takeLatest(UserActionTypes.SIGN_OUT_START, signOutStart);
|
||||
}
|
||||
|
||||
|
||||
export function* userSagas() {
|
||||
yield all([
|
||||
// call(onGoogleSignInStart),
|
||||
call(onEmailSignInStart),
|
||||
call(onCheckUserSession),
|
||||
call(onSignOutStart)
|
||||
call(onSignOutStart),
|
||||
// call(onEmailSignUpStart),
|
||||
// call(onEmailSignUpSuccess)
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user