Comments (7)
@mattkrick couple of thoughts there on local storage ^
from redux-auth-wrapper.
You'll also need an authError
state, because if both isAuth
and isAuthing
are false, you don't know whether the whole thing failed, or the whole thing hasn't started yet.
from redux-auth-wrapper.
Yup good call, luckily this is a common pattern for redux actions and should be familiar with most people i.e. LOGIN_SUBMITTED/FAILED/SUCCESS
for constants
from redux-auth-wrapper.
good idea, and if you got a logout exemple i'll be interested as well :)
from redux-auth-wrapper.
See #35 for an ability to display a component while asynchronously performing the login request
from redux-auth-wrapper.
My suggestion for this is using local storage in the action for LOGIN_SUCCESS/LOGOUT_SUCCESS as well as the initialState for the auth reducer:
In LOGIN_SUCCESS, you do something along the lines of:
localStorage.setItem('jwt_token', response.token)
Then in LOGOUT_SUCCESS, you clear the item:
localStorage.removeItem('jwt_token')
and finally in the initialState for your auth reducer:
const auth = (state = {
isAuthenticated: localStorage.getItem('jwt_token') ? true : false
}, action) => {
...
Obviously you could do a similar thing for other implementations of auth that aren't JWT.
This way, you can persist login on refresh. Thoughts?
from redux-auth-wrapper.
@johnwiseheart yup I think that should work pretty well. You could also go one step further and use a setTimeout or kick off a saga to clear the token locally and clear the auth reducer if the token or cookie has an expiration date. Seems to me that the necessary features for this are probably all set, just want an example since its a common use case
from redux-auth-wrapper.
Related Issues (20)
- [Possible Bug] Async Validation in a multi-step form HOT 1
- How to make chunk js with react-router HOT 1
- Error in UserAuthWrapper
- Hande logout when expired token in axios interceptors but not redirect to login page HOT 2
- Misleading naming of authenticatedSelector HOT 2
- Example with react 16.x HOT 1
- Reducer not yet defined HOT 2
- Usage with react-cookies
- not running when am trying do npm start HOT 1
- connectedReduxRedirect is missing HOT 1
- Deprecated lifecycle method in redirect.js HOT 7
- Doesn't work with latest react HOT 3
- Type {} is missing the following properties from type Readonly<InjectedAuthProps> HOT 1
- ES6 Module - Error when using with Electron HOT 2
- redirect.js replace UNSAFE_componentWillMount with componentDidMount HOT 6
- No question mark befor query param on redirect HOT 2
- Versioning Order HOT 4
- React-router v6 HOT 9
- Infinite loop (redirect ) with nesting wrappers HOT 1
- Call for mantainers! HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-auth-wrapper.