What is the appropriate way to use/setup next-auth/middlware's config matcher? #4996
-
Hi all, At the moment, I am just trying to do the strategy outline in the Basic usage with the matcher to restrict access to certain routes, but after logging in, the middleware still kicks me back to the signin page. If I don't use the middleware, I can use The I feel like there is more that I need to add to the middleware (2 lines of code can't be it), or there might be something that I'm missing at the // from /src/middleware.ts
export { default } from 'next-auth/middleware';
export const config = { matcher: ['/events', '/users/:id*', '/welcome' /*...etc*/] }; // example welcome page
// /src/pages/welcome.tsx
import { useSession } from "next-auth/react"
const Welcome = () => {
const { data: session, status } = useSession()
console.log('SESSION', session)
console.log('STATUS', status)
if (status === "loading") {
return <p>Loading...</p>
}
if (status === "unauthenticated") {
return <p>Access Denied</p>
}
return (
<>
<h1>Protected Page</h1>
<p>You can view this page because you are signed in.</p>
</>
)
}
export default Welcome Thanks for your help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@rdbarr and I work together, so I'm bumping the question and adding some clarification for our use case. Using the boilerplate
It redirects to my custom
The |
Beta Was this translation helpful? Give feedback.
@rdbarr and I work together, so I'm bumping the question and adding some clarification for our use case. Using the boilerplate
withAuth
is technically working:It redirects to my custom
sign-in
page, but it's blank, and the console is showing this error in 6 files:Uncaught SyntaxError: Unexpected token '<'
.The
sign-in
page doesn't return that error if it's not redirected there from middleware.