From c2bd1c4e6079b07634deea3e526e1491f7f4264b Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Mon, 27 Jul 2026 14:00:37 -0300 Subject: [PATCH] refactor(auth): remove development auth bypass (cherry picked from commit 01425aa97f43bd351a378b3f41400f07aeee3bb0) --- src/api/api.ts | 3 +-- src/domain/auth/api/auth-api.ts | 13 ------------ src/lib/auth/auth-bypass.ts | 36 --------------------------------- src/lib/env.ts | 1 - src/vite-env.d.ts | 2 -- 5 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 src/lib/auth/auth-bypass.ts diff --git a/src/api/api.ts b/src/api/api.ts index 19c29d81..d27d3365 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -5,7 +5,6 @@ import { API_PATHS } from "@/api/api-paths"; import { mapHttpStatusToMessage, normalizeApiRequestError } from "@/api/api-error"; import { queryKeys } from "@/infra/query-key/query-key"; import queryClient from "@/lib/query/query-client"; -import { isAuthBypassEnabled } from "@/lib/auth/auth-bypass"; import { clearAuth, getAccessToken } from "@/lib/auth/auth-storage"; function clearSessionAndRedirectToLogin(): void { @@ -48,7 +47,7 @@ export const api: KyInstance = ky.create({ beforeError: [({ error }) => normalizeApiRequestError(error)], afterResponse: [ ({ request, response }) => { - if (response.status !== 401 || isAuthLoginRequest(request) || isAuthBypassEnabled()) { + if (response.status !== 401 || isAuthLoginRequest(request)) { return response; } diff --git a/src/domain/auth/api/auth-api.ts b/src/domain/auth/api/auth-api.ts index bdbafe16..279baaa7 100644 --- a/src/domain/auth/api/auth-api.ts +++ b/src/domain/auth/api/auth-api.ts @@ -6,11 +6,6 @@ import { API_PATHS } from "@/api/api-paths"; import { apiPost } from "@/api/api"; import { handleApiResponse } from "@/api/handle-api-response"; -import { - disableAuthBypassForSession, - getBypassAuthUser, - isAuthBypassEnabled, -} from "@/lib/auth/auth-bypass"; import { clearAuth, getAuthUser, isSessionValid, setAuthUser } from "@/lib/auth/auth-storage"; import type { AuthUser, @@ -27,18 +22,10 @@ export async function login(credentials: LoginCredentials): Promise { } export async function logout(): Promise { - if (isAuthBypassEnabled()) { - disableAuthBypassForSession(); - } - clearAuth(); } export async function getSession(): Promise { - if (isAuthBypassEnabled()) { - return getBypassAuthUser(); - } - const user = getAuthUser(); if (!user || !isSessionValid(user)) { diff --git a/src/lib/auth/auth-bypass.ts b/src/lib/auth/auth-bypass.ts deleted file mode 100644 index 40e12fea..00000000 --- a/src/lib/auth/auth-bypass.ts +++ /dev/null @@ -1,36 +0,0 @@ -import type { AuthUser } from "@/domain/auth/types/auth-user"; -import { env } from "@/lib/env"; - -const BYPASS_DISABLED_KEY = "auth-bypass-disabled"; - -export function isAuthBypassEnabled(): boolean { - if (!env.isDev || !env.authBypass) { - return false; - } - - if (typeof window !== "undefined" && sessionStorage.getItem(BYPASS_DISABLED_KEY)) { - return false; - } - - return true; -} - -export function getBypassAuthUser(): AuthUser { - return { - token: "dev-bypass-token", - expiration: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString(), - email: "dev-bypass@seahaven.test", - userRoles: "Admin", - phoneNumber: "", - fullname: "Dev Bypass User", - id: "dev-bypass", - }; -} - -export function disableAuthBypassForSession(): void { - if (typeof window === "undefined") { - return; - } - - sessionStorage.setItem(BYPASS_DISABLED_KEY, "1"); -} diff --git a/src/lib/env.ts b/src/lib/env.ts index d22d5b55..51b5d14a 100644 --- a/src/lib/env.ts +++ b/src/lib/env.ts @@ -1,5 +1,4 @@ export const env = { apiUrl: import.meta.env.VITE_API_URL?.trim() || "/api", isDev: import.meta.env.DEV, - authBypass: import.meta.env.VITE_AUTH_BYPASS === "true", } as const; diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 7c85de03..4df1f98f 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -3,8 +3,6 @@ interface ImportMetaEnv { readonly VITE_API_URL: string; readonly VITE_API_TARGET: string; - readonly VITE_AUTH_BYPASS?: string; - readonly VITE_WO_TABLE_MOCK?: string; } interface ImportMeta {