Skip to content

Commit 01428bd

Browse files
committed
Missing PKCE is success in email verification flow
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.
1 parent 70b7195 commit 01428bd

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

packages/auth-express/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,13 @@ export class ExpressAuth {
498498
throw new PKCEError("no verification_token in response");
499499
}
500500
if (!verifier) {
501-
throw new PKCEError("no pkce verifier cookie found");
501+
// End user verified email from a different user agent than sign-up.
502+
// This is fine, but the application will need to detect this and
503+
// inform the end user that they will need to initiate a new sign up
504+
// attempt to complete the flow.
505+
return next();
502506
}
507+
503508
const tokenData = await (
504509
await this.core
505510
).verifyEmailPasswordSignup(verificationToken, verifier);

packages/auth-nextjs/src/shared.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface CreateAuthRouteHandlers {
5353
): Promise<Response>;
5454
onEmailVerify(
5555
params: ParamsOrError<
56-
{ tokenData: TokenData },
56+
{ tokenData: TokenData | null },
5757
{ verificationToken?: string }
5858
>,
5959
req: NextRequest,
@@ -357,10 +357,14 @@ export abstract class NextAuth extends NextAuthHelpers {
357357
);
358358
}
359359
if (!verifier) {
360+
// End user verified email from a different user agent than
361+
// sign-up. This is fine, but the application will need to detect
362+
// this and inform the end user that they will need to initiate a
363+
// new sign up attempt to complete the flow.
360364
return onEmailVerify(
361365
{
362-
error: new PKCEError("no pkce verifier cookie found"),
363-
verificationToken,
366+
error: null,
367+
tokenData: null,
364368
},
365369
req,
366370
);

packages/auth-remix/src/server.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export interface CreateAuthRouteHandlers {
8686
): Promise<Response>;
8787
onEmailVerify(
8888
params: ParamsOrError<
89-
{ tokenData: TokenData },
89+
{ tokenData: TokenData | null },
9090
{ verificationToken?: string }
9191
>,
9292
): Promise<Response>;
@@ -422,9 +422,13 @@ export class RemixServerAuth extends RemixClientAuth {
422422
});
423423
}
424424
if (!verifier) {
425+
// End user verified email from a different user agent than
426+
// sign-up. This is fine, but the application will need to detect
427+
// this and inform the end user that they will need to initiate a
428+
// new sign up attempt to complete the flow.
425429
return cbCall(onEmailVerify, {
426-
error: new PKCEError("no pkce verifier cookie found"),
427-
verificationToken,
430+
error: null,
431+
tokenData: null,
428432
});
429433
}
430434
let tokenData: TokenData;

packages/auth-sveltekit/src/server.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface AuthRouteHandlers {
6363
) => Promise<never>;
6464
onEmailVerify?: (
6565
params: ParamsOrError<
66-
{ tokenData: TokenData },
66+
{ tokenData: TokenData | null },
6767
{ verificationToken?: string }
6868
>,
6969
) => Promise<never>;
@@ -653,9 +653,13 @@ async function handleAuthRoutes(
653653
});
654654
}
655655
if (!verifier) {
656+
// End user verified email from a different user agent than sign-up.
657+
// This is fine, but the application will need to detect this and inform
658+
// the end user that they will need to initiate a new sign up attempt to
659+
// complete the flow.
656660
return onEmailVerify({
657-
error: new PKCEError("no pkce verifier cookie found"),
658-
verificationToken,
661+
error: null,
662+
tokenData: null,
659663
});
660664
}
661665
let tokenData: TokenData;

0 commit comments

Comments
 (0)