This commit is contained in:
pradeepkumar
2026-03-31 23:23:16 +05:30
parent f7f308af84
commit 719404b663
5 changed files with 55 additions and 40 deletions

View File

@@ -117,11 +117,13 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
// Read role and agent type from cookies (set by signup page before OAuth redirect)
let role: string | undefined;
let agentTypeId: string | undefined;
let mode: string | undefined;
try {
const { cookies } = await import("next/headers");
const cookieStore = await cookies();
role = cookieStore.get("socialAuthRole")?.value;
agentTypeId = cookieStore.get("socialAuthAgentTypeId")?.value;
mode = cookieStore.get("socialAuthMode")?.value;
} catch {
// Cookie may not be available
}
@@ -139,6 +141,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
avatar: user.image,
role,
agentTypeId,
mode: mode || 'signup',
}),
}
);
@@ -150,6 +153,9 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
(user as any).role = data.data.user.role;
(user as any).accessToken = data.data.accessToken;
(user as any).refreshToken = data.data.refreshToken;
} else if (!res.ok) {
const errorMsg = data?.message || "Social login failed";
return `/login?error=${encodeURIComponent(errorMsg)}`;
}
} catch (error) {
console.error("Social auth sync error:", error);