Skip to content

Commit

Permalink
Fix (trailingSlash: true) causes issue in auth0 example (#27010)
Browse files Browse the repository at this point in the history
I think the issue was due to ```nextjs-auth0``` package on version ```0.8.0```. Upgrading to latest version ```1.4.2``` resolve the issue.

## Bug

- [x] Related issues linked using `fixes` #19313
  • Loading branch information
tanys123 authored Jul 8, 2021
1 parent 841ea04 commit 5e6b920
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
5 changes: 3 additions & 2 deletions examples/auth0/.env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
NEXT_PUBLIC_AUTH0_CLIENT_ID=
NEXT_PUBLIC_AUTH0_SCOPE="openid profile"
NEXT_PUBLIC_AUTH0_DOMAIN=
NEXT_PUBLIC_REDIRECT_URI="http://localhost:3000/api/callback"
NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI="http://localhost:3000"
NEXT_PUBLIC_BASE_URL="http://localhost:3000"
NEXT_PUBLIC_REDIRECT_URI="/api/callback"
NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI="/"

# Secret environment variables only available to Node.js
AUTH0_CLIENT_SECRET=
Expand Down
5 changes: 3 additions & 2 deletions examples/auth0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ Then, open `.env.local` and add the missing environment variables:
- `NEXT_PUBLIC_AUTH0_DOMAIN` - Can be found in the Auth0 dashboard under `settings`.
- `NEXT_PUBLIC_AUTH0_CLIENT_ID` - Can be found in the Auth0 dashboard under `settings`.
- `AUTH0_CLIENT_SECRET` - Can be found in the Auth0 dashboard under `settings`.
- `NEXT_PUBLIC_REDIRECT_URI` - The url where Auth0 redirects back to, make sure a consistent url is used here.
- `NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI` - Where to redirect after logging out
- `NEXT_PUBLIC_BASE_URL` - The base url of the application.
- `NEXT_PUBLIC_REDIRECT_URI` - The relative url path where Auth0 redirects back to.
- `NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI` - Where to redirect after logging out.
- `SESSION_COOKIE_SECRET` - A unique secret used to encrypt the cookies, has to be at least 32 characters. You can use [this generator](https://generate-secret.vercel.app/32) to generate a value.
- `SESSION_COOKIE_LIFETIME` - How long a session lasts in seconds. The default is 2 hours.

Expand Down
28 changes: 17 additions & 11 deletions examples/auth0/lib/auth0.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { initAuth0 } from '@auth0/nextjs-auth0'

export default initAuth0({
clientId: process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID,
secret: process.env.SESSION_COOKIE_SECRET,
issuerBaseURL: process.env.NEXT_PUBLIC_AUTH0_DOMAIN,
baseURL: process.env.NEXT_PUBLIC_BASE_URL,
clientID: process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
scope: process.env.NEXT_PUBLIC_AUTH0_SCOPE || 'openid profile',
domain: process.env.NEXT_PUBLIC_AUTH0_DOMAIN,
redirectUri:
process.env.NEXT_PUBLIC_REDIRECT_URI ||
'http://localhost:3000/api/callback',
postLogoutRedirectUri:
process.env.NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI ||
'http://localhost:3000/',
routes: {
callback:
process.env.NEXT_PUBLIC_REDIRECT_URI ||
'http://localhost:3000/api/callback',
postLogoutRedirect:
process.env.NEXT_PUBLIC_POST_LOGOUT_REDIRECT_URI ||
'http://localhost:3000',
},
authorizationParams: {
response_type: 'code',
scope: process.env.NEXT_PUBLIC_AUTH0_SCOPE,
},
session: {
cookieSecret: process.env.SESSION_COOKIE_SECRET,
cookieLifetime: Number(process.env.SESSION_COOKIE_LIFETIME) || 7200,
absoluteDuration: process.env.SESSION_COOKIE_LIFETIME,
},
})
2 changes: 1 addition & 1 deletion examples/auth0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@auth0/nextjs-auth0": "^0.8.0",
"@auth0/nextjs-auth0": "^1.4.2",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down

0 comments on commit 5e6b920

Please sign in to comment.