Credentials
#11812
Replies: 1 comment 1 reply
-
See my comment on this issue here and see if this is your problem, if so, the solution I found will solve the problem: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys, not sure whats wrong with my login, it works perfectly well on localhost, but when I deploy to vercel, it successfully retrieve the data but ,logs out almost immediately, I tried adding the NEXTAUTH_URL but still getting the same issue,
it works when i use localhost:3000 as the NEXTAUTH_URL but soon as i add my vercel.app domain, it fails to load the dashboard
import NextAuth from "next-auth";
import authConfig from "@/auth.config";
import { getToken } from "next-auth/jwt";
import {
DEFAULT_LOGIN_REDIRECT,
apiAuthPrefix,
authRoutes,
publicRoutes,
DEFAULT_USER_ROLE,
} from "@/routes";
import { NextRequest } from "next/server";
const { auth } = NextAuth(authConfig);
//@ts-ignore
export default auth(async (req) => {
const { nextUrl } = req;
// console.log(req.url, "request url");
// console.log(nextUrl, "next url");
try {
const token = await getToken({
req,
//@ts-ignore
secret: process.env.NEXTAUTH_SECRET,
});
const userRole = token?.role;
} catch (error) {
console.error("Error fetching token:", error);
// Handle error, e.g., redirect to login or display an error message
return Response.redirect(new URL("/login", nextUrl));
}
});
export const config = {
matcher: ["/((?!.\..|_next).)", "/", "/(api|trpc)(.)"],
unstable_allowDynamic: [
"mongoose/dist/browser.umd.js",
"./(models)/Parent.ts",
"/node_modules/function-bind/**", // use a glob to allow anything in the function-bind 3rd party module
],
};
this is my middleware. any help would be really appreciated
Beta Was this translation helpful? Give feedback.
All reactions