-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathauth.js
30 lines (26 loc) · 1.09 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { connectedRouterRedirect } from 'redux-auth-wrapper/history4/redirect';
import locationHelperBuilder from 'redux-auth-wrapper/history4/locationHelper';
const locationHelper = locationHelperBuilder({});
export const userIsAuthenticated = connectedRouterRedirect({
// The url to redirect user to if they fail
redirectPath: '/login',
// Determine if the user is authenticated or not
authenticatedSelector: (state) => state.user.authenticated === true,
// A nice display name for this check
wrapperDisplayName: 'UserIsAuthenticated'
});
export const userIsNotAuthenticated = connectedRouterRedirect({
redirectPath: (state, ownProps) =>
locationHelper.getRedirectQueryParam(ownProps) || '/',
allowRedirectBack: false,
authenticatedSelector: (state) => state.user.authenticated === false,
wrapperDisplayName: 'UserIsNotAuthenticated'
});
export const userIsAuthorized = connectedRouterRedirect({
redirectPath: '/',
allowRedirectBack: false,
authenticatedSelector: (state, ownProps) => {
const { username } = ownProps.params;
return state.user.username === username;
}
});