Skip to content

Commit

Permalink
Enable resendVerificationEmail with email param (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroslavPetrik authored Feb 2, 2024
1 parent fd0be5f commit 265e172
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
7 changes: 7 additions & 0 deletions packages/auth-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ export class Auth {
});
}

async resendVerificationEmailForEmail(email: string) {
await this._post("resend-verification-email", {
provider: emailPasswordProviderName,
email,
});
}

async sendPasswordResetEmail(email: string, resetUrl: string) {
const { challenge, verifier } = await pkce.createVerifierChallengePair();
return {
Expand Down
33 changes: 26 additions & 7 deletions packages/auth-nextjs/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,33 @@ export class NextAppAuth extends NextAuth {
return tokenData;
},
emailPasswordResendVerificationEmail: async (
data: FormData | { verification_token: string }
data: FormData | { verification_token: string } | { email: string }
) => {
const [verificationToken] = _extractParams(
data,
["verification_token"],
"verification_token missing"
);
await (await this.core).resendVerificationEmail(verificationToken);
let email;
let verificationToken;
try {
[verificationToken] = _extractParams(
data,
["verification_token"],
"verification_token missing"
);
} catch (tokenError) {
try {
[email] = _extractParams(data, ["email"], "email missing");
} catch (emailError) {
const bothParamsMissing = [tokenError, emailError]
.map((err) => (err as Error).message)
.join(" and ");

throw new Error(`${bothParamsMissing}. Either one is required.`);
}
}

if (verificationToken) {
await (await this.core).resendVerificationEmail(verificationToken);
} else if (email) {
await (await this.core).resendVerificationEmailForEmail(email);
}
},
};
}
Expand Down

0 comments on commit 265e172

Please sign in to comment.