Auth-module: [@nuxtjs/auth-next] login with redirect to previous route.

Created on 18 Jan 2021  路  1Comment  路  Source: nuxt-community/auth-module

"dependencies": {
    "@nuxtjs/auth-next": "^5.0.0-1610809099.bcf293f",
    "@nuxtjs/axios": "^5.12.5",
}

I'm using local auth strategy with Bearer token.

  auth: {
    redirect: {
      login: '/login',
      logout: '/login',
      callback: '/login',
      home: '/',
    },

    strategies: {
      local: {
        token: {
          property: 'accessToken',
          required: true,
          // type: 'Bearer',
        },

        user: {
          property: false,
          // autoFetch: true,
        },

        endpoints: {
          login: { url: '/login', method: 'post' },
          logout: { url: '/users/logout', method: 'post' },
          user: { url: '/users', method: 'get' },
        },
      },
    },
  },

After a successful login, I'm redirected to / as expected and defined in home, but suppose that I'm in a route like /keys and my token expired, which means that I'll be redirected to /login as expected, but I expect that after another successful login, this time I'll be redirected to /keys.

I was doing this (@nuxtjs/auth v4) by myself using a plugin like this one, which looks pretty much the same as here in this core function.

So I'm wondering if I can do that without this plugin using just the new (@nuxtjs/auth-next v5)?

I removed the plugin, set many properties (rewriteRedirects, fullPath), but I couldn't find a way to it to work.

question

Most helpful comment

Ok, as usual after 1 hour I figured out that the only thing I need to do was to comment/remove home: '/' in redirect.

home: User will be redirected to this path after login. (rewriteRedirects will rewrite this path)

It was not clear to me that if I had home set in configuration it will disable the rewriteRedirects to work properly. As English is not my first language, maybe it was my fault to understand, or maybe the documentation is not clear enough about that, and so we need to improve it.

>All comments

Ok, as usual after 1 hour I figured out that the only thing I need to do was to comment/remove home: '/' in redirect.

home: User will be redirected to this path after login. (rewriteRedirects will rewrite this path)

It was not clear to me that if I had home set in configuration it will disable the rewriteRedirects to work properly. As English is not my first language, maybe it was my fault to understand, or maybe the documentation is not clear enough about that, and so we need to improve it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sebmor picture sebmor  路  3Comments

aaronhuisinga picture aaronhuisinga  路  3Comments

dasisyouyu picture dasisyouyu  路  3Comments

nikkanetiya picture nikkanetiya  路  3Comments

yuwacker picture yuwacker  路  3Comments