(request: { payload: LoginRequest })
| 36 | // Login API for to self-managed in password auth mode. |
| 37 | // Throws if the API isn't supported for the deployment/auth mode. |
| 38 | export async function loginOrThrow(request: { payload: LoginRequest }) { |
| 39 | const { authApiBasePath } = getApiClient(); |
| 40 | |
| 41 | const response = await fetch(`${authApiBasePath}/api/login`, { |
| 42 | method: "POST", |
| 43 | headers: { |
| 44 | "Content-Type": "application/json", |
| 45 | }, |
| 46 | body: JSON.stringify(request.payload), |
| 47 | }); |
| 48 | |
| 49 | const responseText = await response.text(); |
| 50 | |
| 51 | if (!response.ok) { |
| 52 | if (response.status === 401) { |
| 53 | throw new Error("Invalid credentials", { |
| 54 | cause: { status: response.status }, |
| 55 | }); |
| 56 | } |
| 57 | throw new Error(responseText, { |
| 58 | cause: { status: response.status }, |
| 59 | }); |
| 60 | } |
| 61 | return responseText; |
| 62 | } |
| 63 | |
| 64 | export async function hasActiveSession(): Promise<boolean> { |
| 65 | const { authApiBasePath } = getApiClient(); |
nothing calls this directly
no test coverage detected