mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
refactor(auth): remove development auth bypass
This commit is contained in:
parent
e023ea3101
commit
ed3bd71b5f
4 changed files with 0 additions and 52 deletions
|
|
@ -6,11 +6,6 @@
|
||||||
import { API_PATHS } from "@/api/api-paths";
|
import { API_PATHS } from "@/api/api-paths";
|
||||||
import { apiPost } from "@/api/api";
|
import { apiPost } from "@/api/api";
|
||||||
import { handleApiResponse } from "@/api/handle-api-response";
|
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 { clearAuth, getAuthUser, isSessionValid, setAuthUser } from "@/lib/auth/auth-storage";
|
||||||
import type {
|
import type {
|
||||||
AuthUser,
|
AuthUser,
|
||||||
|
|
@ -27,18 +22,10 @@ export async function login(credentials: LoginCredentials): Promise<AuthUser> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function logout(): Promise<void> {
|
export async function logout(): Promise<void> {
|
||||||
if (isAuthBypassEnabled()) {
|
|
||||||
disableAuthBypassForSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
clearAuth();
|
clearAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSession(): Promise<AuthUser | null> {
|
export async function getSession(): Promise<AuthUser | null> {
|
||||||
if (isAuthBypassEnabled()) {
|
|
||||||
return getBypassAuthUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = getAuthUser();
|
const user = getAuthUser();
|
||||||
|
|
||||||
if (!user || !isSessionValid(user)) {
|
if (!user || !isSessionValid(user)) {
|
||||||
|
|
|
||||||
|
|
@ -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");
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
export const env = {
|
export const env = {
|
||||||
apiUrl: import.meta.env.VITE_API_URL?.trim() || "/api",
|
apiUrl: import.meta.env.VITE_API_URL?.trim() || "/api",
|
||||||
isDev: import.meta.env.DEV,
|
isDev: import.meta.env.DEV,
|
||||||
authBypass: import.meta.env.VITE_AUTH_BYPASS === "true",
|
|
||||||
} as const;
|
} as const;
|
||||||
|
|
|
||||||
2
src/vite-env.d.ts
vendored
2
src/vite-env.d.ts
vendored
|
|
@ -3,8 +3,6 @@
|
||||||
interface ImportMetaEnv {
|
interface ImportMetaEnv {
|
||||||
readonly VITE_API_URL: string;
|
readonly VITE_API_URL: string;
|
||||||
readonly VITE_API_TARGET: string;
|
readonly VITE_API_TARGET: string;
|
||||||
readonly VITE_AUTH_BYPASS?: string;
|
|
||||||
readonly VITE_WO_TABLE_MOCK?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ImportMeta {
|
interface ImportMeta {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue