@@ -109,3 +109,13 @@ export const setAuthlevel = (authlevel) => ({
|
||||
type: UserActionTypes.SET_AUTH_LEVEL,
|
||||
payload: authlevel,
|
||||
});
|
||||
|
||||
export const setCurrentEula = (eula) => ({
|
||||
type: UserActionTypes.SET_CURRENT_EULA,
|
||||
payload: eula,
|
||||
});
|
||||
|
||||
export const acceptEula = () => ({
|
||||
type: UserActionTypes.EULA_ACCEPTED,
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import UserActionTypes from "./user.types";
|
||||
const INITIAL_STATE = {
|
||||
currentUser: {
|
||||
authorized: null,
|
||||
eulaIsAccepted: false,
|
||||
//language: "en-US"
|
||||
},
|
||||
bodyshop: null,
|
||||
@@ -17,6 +18,7 @@ const INITIAL_STATE = {
|
||||
loading: false,
|
||||
},
|
||||
authLevel: 0,
|
||||
currentEula: null,
|
||||
};
|
||||
|
||||
const userReducer = (state = INITIAL_STATE, action) => {
|
||||
@@ -63,11 +65,19 @@ const userReducer = (state = INITIAL_STATE, action) => {
|
||||
loading: false,
|
||||
},
|
||||
};
|
||||
case UserActionTypes.EULA_ACCEPTED:
|
||||
return {
|
||||
...state,
|
||||
currentUser:{...state.currentUser, eulaIsAccepted: true},
|
||||
currentEula: null,
|
||||
};
|
||||
case UserActionTypes.SIGN_IN_SUCCESS:
|
||||
const{ currentEula,...currentUser} = action.payload
|
||||
return {
|
||||
...state,
|
||||
loginLoading: false,
|
||||
currentUser: action.payload,
|
||||
currentUser: currentUser,
|
||||
currentEula,
|
||||
error: null,
|
||||
};
|
||||
case UserActionTypes.SIGN_OUT_SUCCESS:
|
||||
|
||||
@@ -43,6 +43,9 @@ import {
|
||||
validatePasswordResetSuccess,
|
||||
} from "./user.actions";
|
||||
import UserActionTypes from "./user.types";
|
||||
import client from "../../utils/GraphQLClient";
|
||||
import {QUERY_EULA} from "../../graphql/bodyshop.queries";
|
||||
import day from "../../utils/day";
|
||||
|
||||
const fpPromise = FingerprintJS.load();
|
||||
|
||||
@@ -73,6 +76,8 @@ export function* signInWithEmail({ payload: { email, password } }) {
|
||||
export function* onCheckUserSession() {
|
||||
yield takeLatest(UserActionTypes.CHECK_USER_SESSION, isUserAuthenticated);
|
||||
}
|
||||
|
||||
|
||||
export function* isUserAuthenticated() {
|
||||
try {
|
||||
logImEXEvent("redux_auth_check");
|
||||
@@ -85,6 +90,15 @@ export function* isUserAuthenticated() {
|
||||
|
||||
LogRocket.identify(user.email);
|
||||
|
||||
const eulaQuery = yield client.query({
|
||||
query: QUERY_EULA,
|
||||
variables: {
|
||||
now: day()
|
||||
},
|
||||
});
|
||||
|
||||
const eulaIsAccepted = eulaQuery.data.eulas.length > 0 && eulaQuery.data.eulas[0].eula_acceptances.length > 0;
|
||||
|
||||
yield put(
|
||||
signInSuccess({
|
||||
uid: user.uid,
|
||||
@@ -92,6 +106,8 @@ export function* isUserAuthenticated() {
|
||||
displayName: user.displayName,
|
||||
photoURL: user.photoURL,
|
||||
authorized: true,
|
||||
eulaIsAccepted,
|
||||
currentEula: eulaIsAccepted ? null : eulaQuery.data.eulas[0],
|
||||
})
|
||||
);
|
||||
} catch (error) {
|
||||
|
||||
@@ -36,3 +36,8 @@ export const selectLoginLoading = createSelector(
|
||||
[selectUser],
|
||||
(user) => user.loginLoading
|
||||
);
|
||||
|
||||
export const selectCurrentEula = createSelector(
|
||||
[selectUser],
|
||||
(user) => user.currentEula
|
||||
);
|
||||
|
||||
@@ -32,5 +32,7 @@ const UserActionTypes = {
|
||||
CHECK_ACTION_CODE_START: "CHECK_ACTION_CODE_START",
|
||||
CHECK_ACTION_CODE_SUCCESS: "CHECK_ACTION_CODE_SUCCESS",
|
||||
CHECK_ACTION_CODE_FAILURE: "CHECK_ACTION_CODE_FAILURE",
|
||||
SET_CURRENT_EULA: "SET_CURRENT_EULA",
|
||||
EULA_ACCEPTED : "EULA_ACCEPTED",
|
||||
};
|
||||
export default UserActionTypes;
|
||||
|
||||
Reference in New Issue
Block a user