Skip to content

Commit

Permalink
Return the provider to onOAuthCallback and onBuiltinUICallback
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclarke committed Nov 16, 2023
1 parent 5e8105b commit f1dcf75
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions packages/auth-nextjs/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ type ParamsOrError<Result extends object, ErrorDetails extends object = {}> =

export interface CreateAuthRouteHandlers {
onOAuthCallback(
params: ParamsOrError<{ tokenData: TokenData; isSignUp: boolean }>
params: ParamsOrError<{
tokenData: TokenData;
provider: BuiltinOAuthProviderNames;
isSignUp: boolean;
}>
): void;
onEmailPasswordSignIn(params: ParamsOrError<{ tokenData: TokenData }>): void;
onEmailPasswordSignUp(
Expand All @@ -43,7 +47,15 @@ export interface CreateAuthRouteHandlers {
>
): void;
onBuiltinUICallback(
params: ParamsOrError<{ tokenData: TokenData | null; isSignUp: boolean }>
params: ParamsOrError<
(
| {
tokenData: TokenData;
provider: BuiltinProviderNames;
}
| { tokenData: null; provider: null }
) & { isSignUp: boolean }
>
): void;
onSignout(): void;
}
Expand Down Expand Up @@ -154,7 +166,14 @@ export class NextAppAuth extends NextAuth {
});
cookies().delete(this.options.pkceVerifierCookieName);

return onOAuthCallback({ error: null, tokenData, isSignUp });
return onOAuthCallback({
error: null,
tokenData,
provider: req.nextUrl.searchParams.get(
"provider"
) as BuiltinOAuthProviderNames,
isSignUp,
});
}
case "emailpassword/verify": {
if (!onEmailVerify) {
Expand Down Expand Up @@ -222,6 +241,7 @@ export class NextAppAuth extends NextAuth {
return onBuiltinUICallback({
error: null,
tokenData: null,
provider: null,
isSignUp: true,
});
}
Expand Down Expand Up @@ -255,7 +275,14 @@ export class NextAppAuth extends NextAuth {
});
cookies().delete(this.options.pkceVerifierCookieName);

return onBuiltinUICallback({ error: null, tokenData, isSignUp });
return onBuiltinUICallback({
error: null,
tokenData,
provider: req.nextUrl.searchParams.get(
"provider"
) as BuiltinProviderNames,
isSignUp,
});
}
case "builtin/signin":
case "builtin/signup": {
Expand Down

0 comments on commit f1dcf75

Please sign in to comment.