Add hasNot
to redirects
#34052
corysimmons
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
Hi, Middleware might give you much more flexibility. https://nextjs.org/docs/middleware Auth libraries like NextAuth.js can also wrap this for you, and make the configuration a single line in some cases: https://next-auth.js.org/configuration/nextjs#middleware // Lock down your entire page
// pages/_middleware.js
export { default } from "next-auth/middleware"
//or
// Lock down your /admin/* pages, requiring a special role
// pages/admin/_middleware.js
import { withAuth } from "next-auth/middleware"
export default withAuth({
callbacks: {
authorized: ({ token }) => token?.role === "admin"
}
}) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the feature you'd like to request
I'd love to be able to redirect people to a login page if
hasNot: someAuthCookieKey
...has
exists.Describe the solution you'd like
Add a
hasNot
or just allow full-blown regex matching instead of only being able to match after xyz.Describe alternatives you've considered
You can redirect from within the app, but I'm always torn about whether I should use
next.config.js
to do redirects or just manually do them from within the app. It feels like thenext.config.js
approach is better/faster, but running into weird things like this make me want to delete it and just roll everything from within components. :(From googling this seems like a pretty common request where people are just like "It's not available. 🤷♂️" and it also seems pretty easy to add.
Beta Was this translation helpful? Give feedback.
All reactions