Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪟 🔧 Cleaner error handling for authService's sendVerificationEmail #21763

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ export const useShowEnrollmentModal = () => {
const { registerNotification } = useNotificationService();

const verifyEmail = () =>
sendEmailVerification()
.then(() => {
registerNotification({
id: "fcp/verify-email",
text: formatMessage({ id: "freeConnectorProgram.enrollmentModal.validationEmailConfirmation" }),
type: ToastType.INFO,
});
})
.catch(); // don't crash the page on error
sendEmailVerification().then(() => {
registerNotification({
id: "fcp/verify-email",
text: formatMessage({ id: "freeConnectorProgram.enrollmentModal.validationEmailConfirmation" }),
type: ToastType.INFO,
});
});

return {
showEnrollmentModal: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ export const AuthenticationProvider: React.FC<React.PropsWithChildren<unknown>>
await authService.resetPassword(email);
},
async sendEmailVerification(): Promise<void> {
try {
await authService.sendEmailVerifiedLink();
} catch (error) {
return authService.sendEmailVerifiedLink().catch((error) => {
switch (error.code) {
case AuthErrorCodes.NETWORK_REQUEST_FAILED:
registerNotification({
Expand Down Expand Up @@ -273,8 +271,7 @@ export const AuthenticationProvider: React.FC<React.PropsWithChildren<unknown>>
type: ToastType.ERROR,
});
}
throw error;
}
});
},
async verifyEmail(code: string): Promise<void> {
await authService.confirmEmailVerify(code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const EmailVerificationHint: React.FC<Props> = ({ className }) => {

const onResendVerificationMail = async () => {
// the shared error handling inside `sendEmailVerification` suffices
await sendEmailVerification().catch();
await sendEmailVerification();
setIsEmailResend(true);
};

Expand Down