Merged in feature/sas-login (pull request #1256)
First steps towards the SAS partnership * otp flow now pretends to do the linking * Update LinkAccountForm header * Update redirect times * Clean up comments * Set maxAge on sas cookies * make all SAS routes protected * Merge remote-tracking branch 'refs/remotes/origin/feature/sas-login' into feature/sas-login * Require auth for sas link flow * Fix resend otp * Add error support to OneTimePasswordForm * Add Sentry to SAS error boundary * Move SAS_REQUEST_OTP_STATE_STORAGE_COOKIE_NAME * Add missing translations * Merge branch 'master' of bitbucket.org:scandic-swap/web into feature/sas-login * Merge branch 'feature/sas-login' of bitbucket.org:scandic-swap/web into feature/sas-login * Add TooManyCodesError component * Refactor GenericError to support new errors * Add FailedAttemptsError * remove removed component <VWOScript/> * Merge branch 'feature/sas-login' of bitbucket.org:scandic-swap/web into feature/sas-login * remove local cookie-bot reference * Fix sas campaign logo scaling * feature toggle the SAS stuff * Merge branch 'feature/sas-login' of bitbucket.org:scandic-swap/web into feature/sas-login * fix: use env vars for SAS endpoints Approved-by: Linus Flood
This commit is contained in:
61
server/routers/partners/sas/otp/request/requestOtpError.ts
Normal file
61
server/routers/partners/sas/otp/request/requestOtpError.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export type RequestOtpResponseError = "TOO_MANY_REQUESTS" | "UNKNOWN"
|
||||
|
||||
const requestOtpGeneralError = z.enum([
|
||||
"AUTH_TOKEN_EXPIRED",
|
||||
"AUTH_TOKEN_NOT_FOUND",
|
||||
"UNKNOWN",
|
||||
])
|
||||
export type RequestOtpGeneralError = z.infer<typeof requestOtpGeneralError>
|
||||
|
||||
export type RequestOtpError = {
|
||||
errorCode: RequestOtpResponseError | RequestOtpGeneralError
|
||||
}
|
||||
export function parseSASRequestOtpError(
|
||||
error: SasOtpRequestError | {}
|
||||
): RequestOtpError {
|
||||
const parseResult = sasOtpRequestErrorSchema.safeParse(error)
|
||||
if (!parseResult.success) {
|
||||
const generalErrorResult = requestOtpGeneralError.safeParse(error)
|
||||
if (!generalErrorResult.success) {
|
||||
return {
|
||||
errorCode: "UNKNOWN",
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
errorCode: generalErrorResult.data,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
errorCode: getErrorCodeByNumber(parseResult.data.errorCode),
|
||||
}
|
||||
}
|
||||
|
||||
const SAS_REQUEST_OTP_ERROR_CODES: {
|
||||
[key in Exclude<RequestOtpResponseError, "UNKNOWN">]: number
|
||||
} = {
|
||||
TOO_MANY_REQUESTS: 10,
|
||||
}
|
||||
|
||||
const getErrorCodeByNumber = (number: number): RequestOtpResponseError => {
|
||||
const v =
|
||||
Object.entries(SAS_REQUEST_OTP_ERROR_CODES).find(
|
||||
([_, value]) => value === number
|
||||
)?.[0] ?? "UNKNOWN"
|
||||
|
||||
console.log("[SAS] getErrorCodeByNumber", number, v)
|
||||
return v as RequestOtpResponseError
|
||||
}
|
||||
|
||||
const sasOtpRequestErrorSchema = z.object({
|
||||
status: z.string(),
|
||||
otpExpiration: z.string().datetime(),
|
||||
error: z.string(),
|
||||
errorCode: z.number(),
|
||||
databaseUUID: z.string().uuid(),
|
||||
})
|
||||
|
||||
export type SasOtpRequestError = z.infer<typeof sasOtpRequestErrorSchema>
|
||||
Reference in New Issue
Block a user