Redirect non-emailVerified users to www (#108)

pull/18188/head
Stuart Taylor 2018-05-30 10:11:14 +01:00 committed by Mrugesh Mohapatra
parent 7c372875bf
commit a4adf7283d
6 changed files with 41 additions and 9 deletions

View File

@ -1,3 +1,4 @@
require('dotenv').config();
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
@ -102,6 +103,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
});
};
const webpack = require('webpack');
const generateBabelConfig = require('gatsby/dist/utils/babel-config');
exports.modifyWebpackConfig = ({ config, stage }) => {
@ -134,6 +136,14 @@ exports.modifyWebpackConfig = ({ config, stage }) => {
}
]
]);
config.plugin('DefinePlugin', webpack.DefinePlugin, [
{
HOME_PATH: JSON.stringify(
process.env.HOME_PATH ||
'http://localhost:3000'
)
}
]);
});
};
/* eslint-disable prefer-object-spread/prefer-object-spread */

View File

@ -1,6 +1 @@
AUTH0_DOMAIN=<auth0-tennant>.auth0.com
AUTH0_CLIENT_ID=this-is-me
AUTH0_NAMESPACE='https://auth-ns.freecodecamp.org/'
DEV_SERVICE_PATH='http://localhost:3000/services'
PROD_SERVICE_PATH=''
HOME_PATH='http://localhost:3000'

View File

@ -1,6 +1,7 @@
/* global HOME_PATH */
import { of } from 'rxjs/observable/of';
import { ofType } from 'redux-observable';
import { types, fetchUserComplete } from './';
import { types, fetchUserComplete, hardGoTo } from './';
import {
switchMap,
filter,
@ -17,7 +18,13 @@ function fetchUserEpic(action$, _, { services }) {
switchMap(() => {
return services.readService$({ service: 'user' }).pipe(
filter(({ entities, result }) => entities && !!result),
map(fetchUserComplete),
map(response => {
const { entities: { user }, result } = response;
if (!user[result].emailVerified) {
return hardGoTo(HOME_PATH);
}
return fetchUserComplete(result);
}),
defaultIfEmpty({ type: 'no-user' }),
catchError(err => {
console.log(err);

View File

@ -0,0 +1,15 @@
/* global HOME_PATH */
import { ofType } from 'redux-observable';
import { tap, ignoreElements } from 'rxjs/operators';
import { types } from './';
export default function hardGoToEpic(action$, _, { location }) {
return action$.pipe(
ofType(types.hardGoTo),
tap(({ payload = HOME_PATH }) => {
location.href = payload;
}),
ignoreElements()
);
}

View File

@ -3,16 +3,18 @@ import { createAction, handleActions } from 'redux-actions';
import { createTypes } from '../../../utils/stateManagment';
import { types as challenge } from '../../templates/Challenges/redux';
import fecthUserEpic from './fetch-user-epic';
import hardGoToEpic from './hard-go-to-epic';
const ns = 'app';
export const epics = [fecthUserEpic];
export const epics = [fecthUserEpic, hardGoToEpic];
export const types = createTypes(
[
'fetchUser',
'fetchUserComplete',
'fetchUserError',
'hardGoTo',
'updateUserSignedIn',
'toggleMapModal'
],
@ -30,6 +32,8 @@ export const fetchUser = createAction(types.fetchUser);
export const fetchUserComplete = createAction(types.fetchUserComplete);
export const fecthUserError = createAction(types.fetchUserError);
export const hardGoTo = createAction(types.hardGoTo);
export const toggleMapModal = createAction(types.toggleMapModal);
export const updateUserSignedIn = createAction(types.updateUserSignedIn);

View File

@ -37,6 +37,7 @@ const rootEpic = combineEpics(analyticsEpic, ...appEpics, ...challengeEpics);
const epicMiddleware = createEpicMiddleware(rootEpic, {
dependencies: {
window: typeof window !== 'undefined' ? window : {},
location: typeof window !== 'undefined' ? window.location : {},
document: typeof window !== 'undefined' ? document : {},
services: servicesCreator(serviceOptions)
}