diff options
Diffstat (limited to 'cmd/mirum-server/web/api/client.ts')
| -rw-r--r-- | cmd/mirum-server/web/api/client.ts | 36 | +0 −36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/cmd/mirum-server/web/api/client.ts b/cmd/mirum-server/web/api/client.ts deleted file mode 100644 --- a/cmd/mirum-server/web/api/client.ts +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Nikolay Govorov -// SPDX-License-Identifier: AGPL-3.0-or-later - -import { createClient, type Interceptor } from "@connectrpc/connect"; -import { createConnectTransport } from "@connectrpc/connect-web"; -import { Console, ErrorReason } from "@/gen/api_pb"; -import { errorReason } from "@/lib/errors"; - -const csrfInterceptor = - (csrfToken: string): Interceptor => - (next) => - async (req) => { - req.header.set("X-CSRF-Token", csrfToken); - return next(req); - }; - -// authInterceptor redirects to /auth/login on Unauthenticated so individual -// callers don't need to handle session expiry explicitly. -const authInterceptor: Interceptor = (next) => async (req) => { - try { - return await next(req); - } catch (err) { - if (errorReason(err) === ErrorReason.UNAUTHENTICATED) { - window.location.assign("/auth/login"); - } - throw err; - } -}; - -export function createConsoleClient(csrfToken: string) { - const transport = createConnectTransport({ - baseUrl: "/api/v1", - interceptors: [csrfInterceptor(csrfToken), authInterceptor], - }); - return createClient(Console, transport); -} |
