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:
14
src/auth.ts
14
src/auth.ts
@@ -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,
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user