Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No login redirect on refresh. #155

Closed
SnooHD opened this issue Apr 21, 2018 · 2 comments
Closed

No login redirect on refresh. #155

SnooHD opened this issue Apr 21, 2018 · 2 comments

Comments

@SnooHD
Copy link
Contributor

SnooHD commented Apr 21, 2018

What problem does this feature solve?

When a user logs in, the user is redirected to home.
When the page is refreshed, the user will be logged in again, and because of that, redirected to home again.
I think that this is bad UX.

What does the proposed changes look like?

I want to disable redirect in case there was a refresh.
Maybe this can be enabled / disabled by adding an option to nuxt.config?

auth: {
   refreshRedirect: false
}

Changing this in the watchState of the init function in /lib/core/auth.js should work:

// Watch for loggedIn changes only in client side
if (process.browser) {
  this.$storage.watchState('loggedIn', loggedIn => {
    if (!routeOption(this.ctx.route, 'auth', false)) {
      //disable redirect after login on refresh / first load.
      if(!this.options.refreshRedirect){
        if(loggedIn && !this.ctx.from){
           return
        }
      }

      this.redirect(loggedIn ? 'home' : 'logout')
    }
  })
}

Not sure if this is the best way of implementing it, but it works for me.

Edit:
Changed the implementation because my previous method didn't redirect on first load even when NOT logged in.

This feature request is available on Nuxt.js community (#c113)
@ghost ghost added the cmty:feature-request label Apr 21, 2018
@SnooHD SnooHD changed the title No redirect on refresh. No login redirect on refresh. Apr 21, 2018
@SnooHD
Copy link
Contributor Author

SnooHD commented Apr 27, 2018

Merged in #158 , so this can be closed.

@SnooHD SnooHD closed this as completed Apr 27, 2018
@toadkicker
Copy link

#158 was reverted, this should be reopened, or link to current issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants