Skip to content

Commit

Permalink
Missing PKCE is success in email verification flow
Browse files Browse the repository at this point in the history
Since end users might verify their email on a different device than
the user agent they initiated the sign up (or sign in) flow with, treat
this as a success condition. The application will need to detect this
case and show a message that confirms that the email is verified, but
that the user will need to sign in to complete.
  • Loading branch information
scotttrinh committed Dec 10, 2024
1 parent 70b7195 commit 01428bd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
7 changes: 6 additions & 1 deletion packages/auth-express/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,13 @@ export class ExpressAuth {
throw new PKCEError("no verification_token in response");
}
if (!verifier) {
throw new PKCEError("no pkce verifier cookie found");
// End user verified email from a different user agent than sign-up.
// This is fine, but the application will need to detect this and
// inform the end user that they will need to initiate a new sign up
// attempt to complete the flow.
return next();
}

const tokenData = await (
await this.core
).verifyEmailPasswordSignup(verificationToken, verifier);
Expand Down
10 changes: 7 additions & 3 deletions packages/auth-nextjs/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface CreateAuthRouteHandlers {
): Promise<Response>;
onEmailVerify(
params: ParamsOrError<
{ tokenData: TokenData },
{ tokenData: TokenData | null },
{ verificationToken?: string }
>,
req: NextRequest,
Expand Down Expand Up @@ -357,10 +357,14 @@ export abstract class NextAuth extends NextAuthHelpers {
);
}
if (!verifier) {
// End user verified email from a different user agent than
// sign-up. This is fine, but the application will need to detect
// this and inform the end user that they will need to initiate a
// new sign up attempt to complete the flow.
return onEmailVerify(
{
error: new PKCEError("no pkce verifier cookie found"),
verificationToken,
error: null,
tokenData: null,
},
req,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/auth-remix/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface CreateAuthRouteHandlers {
): Promise<Response>;
onEmailVerify(
params: ParamsOrError<
{ tokenData: TokenData },
{ tokenData: TokenData | null },
{ verificationToken?: string }
>,
): Promise<Response>;
Expand Down Expand Up @@ -422,9 +422,13 @@ export class RemixServerAuth extends RemixClientAuth {
});
}
if (!verifier) {
// End user verified email from a different user agent than
// sign-up. This is fine, but the application will need to detect
// this and inform the end user that they will need to initiate a
// new sign up attempt to complete the flow.
return cbCall(onEmailVerify, {
error: new PKCEError("no pkce verifier cookie found"),
verificationToken,
error: null,
tokenData: null,
});
}
let tokenData: TokenData;
Expand Down
10 changes: 7 additions & 3 deletions packages/auth-sveltekit/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface AuthRouteHandlers {
) => Promise<never>;
onEmailVerify?: (
params: ParamsOrError<
{ tokenData: TokenData },
{ tokenData: TokenData | null },
{ verificationToken?: string }
>,
) => Promise<never>;
Expand Down Expand Up @@ -653,9 +653,13 @@ async function handleAuthRoutes(
});
}
if (!verifier) {
// End user verified email from a different user agent than sign-up.
// This is fine, but the application will need to detect this and inform
// the end user that they will need to initiate a new sign up attempt to
// complete the flow.
return onEmailVerify({
error: new PKCEError("no pkce verifier cookie found"),
verificationToken,
error: null,
tokenData: null,
});
}
let tokenData: TokenData;
Expand Down

0 comments on commit 01428bd

Please sign in to comment.