Coder Social home page Coder Social logo

Comments (7)

mjrussell avatar mjrussell commented on August 11, 2024

@mattkrick couple of thoughts there on local storage ^

from redux-auth-wrapper.

mattkrick avatar mattkrick commented on August 11, 2024

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.

mjrussell avatar mjrussell commented on August 11, 2024

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.

eMerzh avatar eMerzh commented on August 11, 2024

good idea, and if you got a logout exemple i'll be interested as well :)

from redux-auth-wrapper.

mjrussell avatar mjrussell commented on August 11, 2024

See #35 for an ability to display a component while asynchronously performing the login request

from redux-auth-wrapper.

johnwiseheart avatar johnwiseheart commented on August 11, 2024

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.

mjrussell avatar mjrussell commented on August 11, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.