Merged in fix/too-many-codes-error (pull request #1814)
Fix SAS OTP rate limited error * Fix error for too many codes not showing up Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -83,9 +83,7 @@ export async function GET(
|
||||
stateResult.data.intent === "unlink" ||
|
||||
stateResult.data.intent === "transfer"
|
||||
) {
|
||||
const [data, error] = await safeTry(
|
||||
serverClient().partner.sas.requestOtp({})
|
||||
)
|
||||
const [data, error] = await safeTry(serverClient().partner.sas.requestOtp())
|
||||
if (!data || error) {
|
||||
console.error("[SAS] Failed to request OTP", error)
|
||||
redirect(`/${lang}/sas-x-scandic/error`)
|
||||
@@ -93,12 +91,13 @@ export async function GET(
|
||||
|
||||
switch (data.status) {
|
||||
case "ABUSED":
|
||||
redirect(`/${params.lang}/sas-x-scandic/error?errorCode=tooManyCodes`)
|
||||
case "NOTSENT":
|
||||
redirect(`/${params.lang}/sas-x-scandic/error`)
|
||||
redirect(`/${params.lang}/sas-x-scandic/error?errorCode=tooManyCodes`)
|
||||
case "NULL":
|
||||
case "RETRY":
|
||||
case "EXPIRED":
|
||||
case "PENDING":
|
||||
case "VERIFIED":
|
||||
// These errors should never happen for request, but according to the API spec they can
|
||||
throw new Error(`Unhandled request OTP status ${data.status}`)
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ export default function OneTimePasswordForm({
|
||||
|
||||
setOtp("")
|
||||
requestOtp.reset()
|
||||
requestOtp.mutate({})
|
||||
requestOtp.mutate()
|
||||
setDisableResend(true)
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -15,29 +15,31 @@ import {
|
||||
|
||||
import type { OtpState } from "../getOTPState"
|
||||
|
||||
const inputSchema = z.object({})
|
||||
|
||||
const outputSchema = z.object({
|
||||
status: z.enum([
|
||||
"VERIFIED",
|
||||
"ABUSED",
|
||||
"EXPIRED",
|
||||
"PENDING",
|
||||
"RETRY",
|
||||
"SENT",
|
||||
"NULL",
|
||||
"NOTSENT",
|
||||
]),
|
||||
const successSchema = z.object({
|
||||
status: z.literal("SENT"),
|
||||
referenceId: z.string().uuid(),
|
||||
databaseUUID: z.string().uuid(),
|
||||
otpExpiration: z.number(),
|
||||
otpReceiver: z.string(),
|
||||
})
|
||||
|
||||
const failureSchema = z.object({
|
||||
status: z.enum([
|
||||
"VERIFIED",
|
||||
"ABUSED",
|
||||
"EXPIRED",
|
||||
"PENDING",
|
||||
"RETRY",
|
||||
"NULL",
|
||||
"NOTSENT",
|
||||
]),
|
||||
})
|
||||
|
||||
const outputSchema = z.union([successSchema, failureSchema])
|
||||
|
||||
export const requestOtp = protectedProcedure
|
||||
.input(inputSchema)
|
||||
.output(outputSchema)
|
||||
.mutation(async function ({ ctx, input }) {
|
||||
.mutation(async function () {
|
||||
const sasAuthToken = getSasToken()
|
||||
|
||||
if (!sasAuthToken) {
|
||||
@@ -63,7 +65,9 @@ export const requestOtp = protectedProcedure
|
||||
throw createError(parseResult.error)
|
||||
}
|
||||
|
||||
setSASOtpCookie(parseResult.data)
|
||||
if (parseResult.data.status === "SENT") {
|
||||
setSASOtpCookie(parseResult.data)
|
||||
}
|
||||
|
||||
return parseResult.data
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user