auth-module
auth-module copied to clipboard
Redirect fail due to removal of trailing slash
Version
module: nuxt:
Nuxt configuration
mode:
- [x] universal
- [ ] spa
Nuxt configuration
router: {
trailingSlash: true,
},
auth: {
strategies: {
social: {
scheme: "oauth2",
endpoints: {
authorization: process.env.API_ADMIN_AJAX_URL + 'oauth/authorize',
token: process.env.API_ADMIN_AJAX_URL + 'oauth/token',
userInfo: false,
logout: false,
},
token: {
property: 'access_token',
type: 'Bearer',
maxAge: 1800
},
refreshToken: {
property: 'refresh_token',
maxAge: 60 * 60 * 24
},
responseType: 'code',
grantType: 'authorization_code',
clientId: process.env.WP_OAUTH_CLIENT_ID,
}
},
redirect: {
login: '/login/',
logout: false,
home: '/',
callback: '/callback/',
},
rewriteRedirects: true,
fullPathRedirect: true,
localStorage: false,
cookie: {
options: {
secure: process.env.ENV !== 'development'
}
},
}
Additional information
We have the trailingSlash option in Nuxt set to true (https://nuxtjs.org/docs/configuration-glossary/configuration-router#trailingslash). We have searched through the code and found the normalizePath function which removes the trailing slash. This should not happen if Nuxt is configured to force trailing slashes. https://github.com/nuxt-community/auth-module/blob/5.0.0-dev/src/utils/index.ts#L67
What is expected?
I expect that after authorization the user is redirect tot /callback/?code=XXX.
What is actually happening?
The user is redirected to /callback?code=XXX.
Checklist
- [x] I have tested with the latest Nuxt version and the issue still occurs
- [x] I have tested with the latest module version and the issue still occurs
- [x] I have searched the issue tracker and this issue hasn't been reported yet
Try it as a temporary workaround this.
// middleware/trailing-slash.js
export default ({ route, redirect }) => {
if (route.path.slice(-1) !== '/') redirect(301, route.path + '/')
}
// nuxt.config.js
{
// ...
router: {
trailingSlash: true,
middleware: ['trailing-slash'],
},
// ...
}