const handleTokenSubmission = ({ code }: { code: string }) => {
mutate(
{ token: code },
{
onSuccess: Either.match({
onLeft: (error) => {
switch (error._tag) {
case "AuthenticationProcessExpiredError": {
return toast.error(t('errors.tokenExpired.title'), {
action: {
label: t('errors.tokenExpired.action'),
onClick: () => setRegistrationState(null),
},
})
}
case "InvalidAuthenticationProcessTokenError": {
return toast.error(t('errors.tokenInvalid.title'), {
action: {
label: t('errors.tokenInvalid.action'),
onClick: () => setRegistrationState(null),
},
})
}
default: {
return toast.error(t('errors.internalError.title'), {
action: {
label: t('errors.internalError.action'),
onClick: () => setRegistrationState(null),
},
})
}
}
},
onRight: ({nextStage}) => {
if (nextStage === 'TWO_FACTOR_REQUIRED') {
navigate(href('/login/2fa'));
} else {
navigate(redirectTo ?? '/');
}
}
}),
},
);
};
const handleTokenSubmission = ({ code }: { code: string }) => {
mutate(
{ token: code },
{
onSuccess: Either.match({
onLeft: (error) => {
switch (error._tag) {
case "AuthenticationProcessExpiredError": {
return toast.error(t('errors.tokenExpired.title'), {
action: {
label: t('errors.tokenExpired.action'),
onClick: () => setRegistrationState(null),
},
})
}
case "InvalidAuthenticationProcessTokenError": {
return toast.error(t('errors.tokenInvalid.title'), {
action: {
label: t('errors.tokenInvalid.action'),
onClick: () => setRegistrationState(null),
},
})
}
default: {
return toast.error(t('errors.internalError.title'), {
action: {
label: t('errors.internalError.action'),
onClick: () => setRegistrationState(null),
},
})
}
}
},
onRight: ({nextStage}) => {
if (nextStage === 'TWO_FACTOR_REQUIRED') {
navigate(href('/login/2fa'));
} else {
navigate(redirectTo ?? '/');
}
}
}),
},
);
};