I am working on nextjs & nextauth projects, with a custom sign-in page. Below are the configurations
Package.json
"next": "^12.0.8"
"next-auth": "^4.2.1"
[..nextauth].js
pages:{
signIn:'/auth/signin'
},
callbacks: {
async redirect({ url, baseUrl }) {
console.log('redirect : '+url+' : '+baseUrl);
if (url.startsWith(baseUrl)) return url
// Allows relative callback URLs
else if (url.startsWith("/")) return new URL(url, baseUrl).toString()
return baseUrl;
}
}
I have a middleware in my profile folder, this is done to secure the files inside this folder. Which should be visible only when user signin.
Folder Structure :
_middleware.js
export { default } from "next-auth/middleware"
Issue : When i try to open the files inside profile folder, it shows the signin screen(working as expected) after successfully signing in the page doesn't redirect to callback url, it still stays on the signin page.