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
fix: update Middleware #4757
fix: update Middleware #4757
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
🎉 Experimental release published on npm! npm i next-auth@0.0.0-pr.4757.5ac99859 yarn add next-auth@0.0.0-pr.4757.5ac99859 |
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 👍
@balazsorban44 I'm getting |
Note the content of this PR has not been released yet, besides #4757 (comment) I tested this locally just now, and it works. Hard to tell more without a reproduction, but I would suggest opening an issue instead. |
@balazsorban44 The only files I have changed are diff --git a/middleware.ts b/middleware.ts
index 2339882..5d8057c 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -3,9 +3,16 @@ import { withAuth } from "next-auth/middleware"
// More on how NextAuth.js middleware works: https://next-auth.js.org/configuration/nextjs#middleware
export default withAuth({
callbacks: {
- authorized: ({ req, token }) =>
+ authorized: ({ req, token }) => {
+ console.log("============ MIDDLEWARE =============")
+ console.log("req: ", req)
+ console.log("cookies: ", req.cookies)
+ console.log("headers: ", req.headers)
+ console.log("token: ", token)
+ console.log("============ MIDDLEWARE =============")
// /admin requires admin role, but /me only requires the user to be logged in.
- req.nextUrl.pathname !== "/admin" || token?.userRole === "admin",
+ return req.nextUrl.pathname !== "/admin" || token?.userRole === "admin"
+ },
},
})
--- a/pages/api/auth/[...nextauth].ts
+++ b/pages/api/auth/[...nextauth].ts
@@ -4,6 +4,7 @@ import FacebookProvider from "next-auth/providers/facebook"
import GithubProvider from "next-auth/providers/github"
import TwitterProvider from "next-auth/providers/twitter"
import Auth0Provider from "next-auth/providers/auth0"
+import CredentialsProvider from "next-auth/providers/credentials"
// import AppleProvider from "next-auth/providers/apple"
// import EmailProvider from "next-auth/providers/email"
@@ -50,6 +51,22 @@ export const authOptions: NextAuthOptions = {
clientSecret: process.env.AUTH0_SECRET,
issuer: process.env.AUTH0_ISSUER,
}),
+ CredentialsProvider({
+ // The name to display on the sign in form (e.g. 'Sign in with...')
+ name: "Credentials",
+ credentials: {
+ username: { label: "Username", type: "text", placeholder: "jsmith" },
+ password: { label: "Password", type: "password" },
+ },
+ async authorize(credentials, req) {
+ return {
+ name: "test",
+ email: "test@email.com",
+ image: "test.jpg",
+ id: "testabc123",
+ }
+ },
+ }),
],
theme: {
colorScheme: "light", It seems |
Correct, this PR was opened to address these changes as linked in the description above. Once the Middleware changes go live in the next Next.js release, the recommendation will be to use the stable API anyway. Remember, Middleware has been in beta for a while, so this isn't breaking semver either. |
Following: https://nextjs.org/docs/messages/middleware-upgrade-guide#how-to-upgrade
☕️ Reasoning
What changes are being made? What feature/bug is being fixed here?
🧢 Checklist
🎫 Affected issues
Please scout and link issues that might be solved by this PR.
Fixes: INSERT_ISSUE_LINK_HERE
📌 Resources