nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 924 forks source link

Saved original guarded route does not include query parameters #1676

Open tnabil opened 2 years ago

tnabil commented 2 years ago

Version

module: 5.0.0 nuxt: 2.14.12

Nuxt configuration

mode:

Nuxt configuration

  auth: {
    localStorage: true,
    rewriteRedirects: true,
    strategies: {
      ping: {
        scheme: 'oauth2',
        endpoints: {
          authorization: process.env.OAUTH_ISSUER + '/as/authorization.oauth2',
          token: process.env.OAUTH_ISSUER + '/as/token.oauth2',
          userInfo: process.env.OAUTH_ISSUER + '/idp/userinfo.openid',
          logout: process.env.OAUTH_ISSUER + '/idp/startSLO.ping'
        },
        token: {
          property: 'access_token',
          type: 'Bearer',
          maxAge: 1800
        },
        responseType: 'code',
        grantType: 'authorization_code',
        clientId: process.env.OAUTH_CLIENT_ID,
        scope: ['openid', 'profile', 'email'],
        codeChallengeMethod: 'S256',
        autoLogout: true,
        redirectUri: process.env.SITEMAP_URL + '/sso-callback'
      }
    },
    redirect: {
      login: '/login',
      logout: '/logout',
      callback: '/sso-callback',
      home: '/'
    }

Reproduction

:warning: without a minimal reproduction we won't be able to look into your issue

What is expected?

After login, user should be redirected back to the original URL including any query string parameters.

What is actually happening?

User is redirected to original URL without query string parameters

Steps to reproduce

Additional information

This is due to this code from auth.ts only saving the route path or full path without the query

    const from = this.options.fullPathRedirect ? this.ctx.route.fullPath : this.ctx.route.path

    let to = this.options.redirect[name]
    if (!to) {
      return
    }

    // Apply rewrites
    if (this.options.rewriteRedirects) {
      if (name === 'login' && isRelativeURL(from) && !isSameURL(to, from)) {
        this.$storage.setUniversal('redirect', from)
      }

      if (name === 'home') {
        const redirect = this.$storage.getUniversal('redirect')
        this.$storage.setUniversal('redirect', null)

        if (isRelativeURL(redirect)) {
          to = redirect
        }
      }
    }

Checklist

Steps to reproduce

What is expected?

What is actually happening?

Performance analysis?

sunnywpp commented 1 year ago

i have the same problem.

nuxt.config.js

fullPathRedirect: true

begin input url: https://xxxxx/preview?id=1

after login url is changed,id=1 is disappeared. https://xxxxx/preview