Let developers to specify reducer key name
This commit is contained in:
parent
255ee70ab6
commit
e85f39ebe2
|
@ -185,8 +185,16 @@ import SomeProtectedPageComponent from './components/SomeProtectedPageComponent'
|
||||||
import SignInPage from './components/SignInPage'
|
import SignInPage from './components/SignInPage'
|
||||||
import { generateRequireSignInWrapper } from 'redux-token-auth'
|
import { generateRequireSignInWrapper } from 'redux-token-auth'
|
||||||
|
|
||||||
|
// In this example we set `reduxTokenAuth` as reducer key.
|
||||||
|
// You can set other key name as you like.
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
|
hasVerificationBeenAttempted: state.reduxTokenAuth.currentUser.hasVerificationBeenAttempted,
|
||||||
|
isSignedIn: state.reduxTokenAuth.currentUser.isSignedIn
|
||||||
|
})
|
||||||
|
|
||||||
const requireSignIn = generateRequireSignInWrapper({
|
const requireSignIn = generateRequireSignInWrapper({
|
||||||
redirectPathIfNotSignedIn: '/signin',
|
redirectPathIfNotSignedIn: '/signin',
|
||||||
|
mapStateToProps,
|
||||||
})
|
})
|
||||||
|
|
||||||
const history = createBrowserHistory({})
|
const history = createBrowserHistory({})
|
||||||
|
|
|
@ -2,18 +2,18 @@ import * as React from 'react'
|
||||||
import { connect, ConnectedProps } from 'react-redux'
|
import { connect, ConnectedProps } from 'react-redux'
|
||||||
import {
|
import {
|
||||||
GenerateRequireSignInWrapperConfig,
|
GenerateRequireSignInWrapperConfig,
|
||||||
ReduxState,
|
// ReduxState,
|
||||||
} from './types'
|
} from './types'
|
||||||
|
|
||||||
const generateRequireSignInWrapper = (
|
const generateRequireSignInWrapper = (
|
||||||
{ redirectPathIfNotSignedIn }: GenerateRequireSignInWrapperConfig
|
{ redirectPathIfNotSignedIn, mapStateToProps }: GenerateRequireSignInWrapperConfig
|
||||||
) => {
|
) => {
|
||||||
const requireSignInWrapper = (PageComponent: React.ComponentClass | React.FunctionComponent) => {
|
const requireSignInWrapper = (PageComponent: React.ComponentClass | React.FunctionComponent) => {
|
||||||
|
|
||||||
const mapStateToProps = (state: ReduxState) => ({
|
// const mapStateToProps = (state: ReduxState) => ({
|
||||||
hasVerificationBeenAttempted: state.reduxTokenAuth.currentUser.hasVerificationBeenAttempted,
|
// hasVerificationBeenAttempted: state.reduxTokenAuth.currentUser.hasVerificationBeenAttempted,
|
||||||
isSignedIn: state.reduxTokenAuth.currentUser.isSignedIn
|
// isSignedIn: state.reduxTokenAuth.currentUser.isSignedIn
|
||||||
})
|
// })
|
||||||
|
|
||||||
const connector = connect(mapStateToProps)
|
const connector = connect(mapStateToProps)
|
||||||
type PropsFromRedux = ConnectedProps<typeof connector>
|
type PropsFromRedux = ConnectedProps<typeof connector>
|
||||||
|
|
|
@ -19,9 +19,9 @@ export interface ReduxTokenAuthState {
|
||||||
readonly currentUser: User
|
readonly currentUser: User
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReduxState {
|
// export interface ReduxState {
|
||||||
readonly reduxTokenAuth: ReduxTokenAuthState
|
// readonly reduxTokenAuth: ReduxTokenAuthState
|
||||||
}
|
// }
|
||||||
|
|
||||||
export interface AuthHeaders {
|
export interface AuthHeaders {
|
||||||
readonly 'access-token': string
|
readonly 'access-token': string
|
||||||
|
@ -182,7 +182,7 @@ export type ReduxAction = RegistrationRequestSentAction
|
||||||
|
|
||||||
export type AppThunk<ReturnType = Promise<void>> = ThunkAction<
|
export type AppThunk<ReturnType = Promise<void>> = ThunkAction<
|
||||||
ReturnType,
|
ReturnType,
|
||||||
ReduxState,
|
object,
|
||||||
unknown,
|
unknown,
|
||||||
Action<string>
|
Action<string>
|
||||||
>
|
>
|
||||||
|
@ -207,6 +207,7 @@ export interface SingleLayerStringMap {
|
||||||
|
|
||||||
export interface GenerateRequireSignInWrapperConfig {
|
export interface GenerateRequireSignInWrapperConfig {
|
||||||
readonly redirectPathIfNotSignedIn: string
|
readonly redirectPathIfNotSignedIn: string
|
||||||
|
readonly mapStateToProps: (state: object) => {hasVerificationBeenAttempted: boolean, isSignedIn: boolean}
|
||||||
}
|
}
|
||||||
|
|
||||||
// export type RequireSignInWrapper = (PageComponent: ComponentClass) => ComponentClass
|
// export type RequireSignInWrapper = (PageComponent: ComponentClass) => ComponentClass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user