( path: string, decode: (value: unknown) => Option.Option<A>, body?: Readonly<Record<string, string>>, )
| 35 | const decodeCanceled = Schema.decodeUnknownOption(Canceled); |
| 36 | |
| 37 | function request<A>( |
| 38 | path: string, |
| 39 | decode: (value: unknown) => Option.Option<A>, |
| 40 | body?: Readonly<Record<string, string>>, |
| 41 | ): Effect.Effect<A, VerificationError> { |
| 42 | return Effect.gen(function* () { |
| 43 | const { response, raw } = yield* Effect.gen(function* () { |
| 44 | const client = yield* HttpClient.HttpClient; |
| 45 | const url = `/api/auth/admin-mfa${path}`; |
| 46 | const base = body === undefined ? HttpClientRequest.get(url) : HttpClientRequest.post(url); |
| 47 | const payload = body === undefined ? base : yield* HttpClientRequest.bodyJson(base, body); |
| 48 | const response = yield* client.execute( |
| 49 | HttpClientRequest.setHeaders(payload, getExecutorOrganizationHeaders()), |
| 50 | ); |
| 51 | const raw = yield* response.json; |
| 52 | return { response, raw }; |
| 53 | }).pipe( |
| 54 | Effect.provide(FetchHttpClient.layer), |
| 55 | Effect.mapError(() => new VerificationError({ message: unavailable })), |
| 56 | ); |
| 57 | if (response.status < 200 || response.status >= 300) { |
| 58 | const message = Option.getOrNull(decodeMessage(raw)); |
| 59 | return yield* new VerificationError({ message: message?.message ?? unavailable }); |
| 60 | } |
| 61 | const parsed = decode(raw); |
| 62 | if (Option.isNone(parsed)) return yield* new VerificationError({ message: unavailable }); |
| 63 | return parsed.value; |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | /** Require a second factor before mounting the organization settings page. */ |
| 68 | export function AdminVerification({ children }: { readonly children: ReactNode }) { |
no test coverage detected