261012_01_FST: first commit
This commit is contained in:
8
src/lib/env.client.ts
Normal file
8
src/lib/env.client.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createEnv, env } from "@kri/common/config";
|
||||
|
||||
export const clientEnv = createEnv({
|
||||
ENV: env.required("NEXT_PUBLIC_ENV", process.env.NEXT_PUBLIC_ENV),
|
||||
API_BASE: env.required("NEXT_PUBLIC_API_BASE", process.env.NEXT_PUBLIC_API_BASE),
|
||||
STORE_KEY: env.required("NEXT_PUBLIC_STORE_KEY", process.env.NEXT_PUBLIC_STORE_KEY),
|
||||
STORE_IV: env.required("NEXT_PUBLIC_STORE_IV", process.env.NEXT_PUBLIC_STORE_IV),
|
||||
});
|
||||
7
src/lib/env.server.ts
Normal file
7
src/lib/env.server.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import "server-only";
|
||||
import { createEnv, env } from "@kri/common/config";
|
||||
|
||||
export const serverEnv = createEnv({
|
||||
ENV: env.required("ENV", process.env.ENV),
|
||||
API_SERVER: env.required("API_SERVER", process.env.API_SERVER),
|
||||
});
|
||||
7
src/lib/http-client.ts
Normal file
7
src/lib/http-client.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { createHttpClient } from "@kri/common/http";
|
||||
import { clientEnv } from "@/lib/env.client";
|
||||
|
||||
const resolveBaseUrl = () =>
|
||||
typeof window === "undefined" ? clientEnv.API_BASE : new URL(clientEnv.API_BASE, window.location.origin).toString();
|
||||
|
||||
export const nextApi = createHttpClient(resolveBaseUrl());
|
||||
13
src/lib/http-server.ts
Normal file
13
src/lib/http-server.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { createHttpClient } from "@kri/common/http";
|
||||
import { serverEnv } from "@/lib/env.server";
|
||||
import { CookieKeys } from "@/store/cookie/cookie-keys";
|
||||
|
||||
export async function createServerApi() {
|
||||
const cookieStore = await cookies();
|
||||
const accessToken = cookieStore.get(CookieKeys.AuthToken)?.value ?? null;
|
||||
return createHttpClient(serverEnv.API_SERVER, {
|
||||
getToken: () => accessToken,
|
||||
defaultHeaders: { "content-type": "application/json" },
|
||||
});
|
||||
}
|
||||
14
src/lib/security.ts
Normal file
14
src/lib/security.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { createSecurity } from "@kri/common/security";
|
||||
import { clientEnv } from "@/lib/env.client";
|
||||
|
||||
export const Security = createSecurity({
|
||||
key: clientEnv.STORE_KEY,
|
||||
iv: clientEnv.STORE_IV,
|
||||
onInvalidConfig: ({ message }) => {
|
||||
if (typeof window === "undefined" || clientEnv.ENV !== "local") return;
|
||||
const target = window as Window & { __kriCryptoConfigAlerted?: boolean };
|
||||
if (target.__kriCryptoConfigAlerted) return;
|
||||
target.__kriCryptoConfigAlerted = true;
|
||||
window.alert(message);
|
||||
},
|
||||
});
|
||||
1
src/lib/utils.ts
Normal file
1
src/lib/utils.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { cn } from "@kri/common/ui";
|
||||
Reference in New Issue
Block a user