我正在使用带有reactsjs的react native,并且在进行一些更改后每次刷新应用程序后都会退出登录。
const client = feathers();
options = {
header: 'Authorization', // the default authorization header for REST
prefix: '', // if set will add a prefix to the header value. for example if prefix was 'JWT' then the header would be 'Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOi...'
path: '/authentication', // the server-side authentication service path
jwtStrategy: 'jwt', // the name of the JWT authentication strategy
entity: 'user', // the entity you are authenticating (ie. a users)
service: 'users', // the service to look up the entity
cookie: 'feathers-jwt', // the name of the cookie to parse the JWT from when cookies are enabled server side
storageKey: 'feathers-jwt', // the key to store the accessToken in localstorage or AsyncStorage on React Native
storage: AsyncStorage
}
client.configure(auth(options))
export const checkAuthorization = () => dispatch => {
AsyncStorage.getItem('feathers-jwt').then(r => {
dispatch({ type: 'CHECK_AUTHORIZATION', payload: r });
return client.passport.verifyJWT(r);
}).then(payload => {
dispatch({ type: 'JWT_PAYLOAD', payload: payload })
return client.service('users').get(payload.userId);
}).then(user => {
client.set('user', user);
client.get('user').then(user => {
dispatch({ type: 'PROFILE', payload: user })
})
})
.catch(() => {
dispatch({ type: 'AUTHORIZATION_FAILED' })
})
除非我自己退出应用程序,否则我希望保持应用程序登录状态。