-
Notifications
You must be signed in to change notification settings - Fork 389
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
[SDK-3554] Next.js Middlware support #815
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
"!<rootDir>/src/handlers/auth.ts", | ||
"!<rootDir>/src/auth0-session/config.ts", | ||
"!<rootDir>/src/auth0-session/index.ts", | ||
"!<rootDir>/src/auth0-session/session-cache.ts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New coverage instrumenter c8 doesn't like files with only TS definitions. (was needed because istanbul instrumented code doesn't run on edge-runtime)
Joi.binary().min(8), | ||
Joi.array().items(Joi.string().min(8), Joi.binary().min(8)) | ||
]).required(), | ||
secret: Joi.alternatives([Joi.string().min(8), Joi.array().items(Joi.string().min(8))]).required(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Joi.binary
(Buffer check) doesn't work on Edge MW
} | ||
return session; | ||
}; | ||
const idTokenValidator = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace changes from eslint --fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a couple minor suggestions.
# Conflicts: # package.json
@@ -11,6 +11,7 @@ | |||
"files": [ | |||
"dist", | |||
"src", | |||
"middleware.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a lone .js file, doesn't it need type defs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, good point - I didn't realise you had to do that. Will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also have to include the typings file here –otherwise it will not be present in the package because it's not inside src
or dist
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d'oh, yep - good point 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just noticed that the typings file also needs to be included in the files
array in the package.json
–otherwise it will not be present in the package because it's not inside src
or dist
.
Hi @Jared-Dev - thanks for testing this out! Looks like you're using |
if (cookies.length || authCookies.length) { | ||
headers.set('set-cookie', [...authCookies, ...cookies].join(', ')); | ||
} | ||
return NextResponse.next({ ...res, headers }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not working as intended for redirects, for some reason. We'll need a test around this as well. See #874.
return NextResponse.next({ ...res, headers }); | |
return NextResponse.next({ ...res, headers, status: res.status }); |
I really am at a loss as to why this is happening, given that ...res
should bringing in the status
property already... Here's the transpiled version:
return [
2 /*return*/,
server_1.NextResponse.next(
tslib_1.__assign(tslib_1.__assign({}, res), {
headers: headers,
status: res.status
})
)
]
📋 Changes
Added a new
withMiddlwareAuthRequired
helper, to protect routes using middleware.To protect all your routes:
To protect specific routes:
For more info see: https://nextjs.org/docs/advanced-features/middleware#matching-paths
To run custom middleware for authenticated users:
📎 References
See #525
https://nextjs.org/docs/advanced-features/middleware
🎯 Testing
Run kitchen-sink example app
Visit http://localhost:3000/profile-mw