feat: Pass user role and agent type via cookies for social sign-up and include them in the social authentication API request.

This commit is contained in:
pradeepkumar
2026-03-26 15:18:12 +05:30
parent 2fccc0a5e3
commit d863fdb1c9
2 changed files with 24 additions and 8 deletions

View File

@@ -114,6 +114,18 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
// For OAuth providers, sync with backend
if (account?.provider === "google" || account?.provider === "facebook" || account?.provider === "twitter") {
try {
// Read role and agent type from cookies (set by signup page before OAuth redirect)
let role: string | undefined;
let agentTypeId: string | undefined;
try {
const { cookies } = await import("next/headers");
const cookieStore = await cookies();
role = cookieStore.get("socialAuthRole")?.value;
agentTypeId = cookieStore.get("socialAuthAgentTypeId")?.value;
} catch {
// Cookie may not be available
}
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/auth/social`,
{
@@ -125,6 +137,8 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
email: user.email,
name: user.name,
avatar: user.image,
role,
agentTypeId,
}),
}
);