261012_01_FST: first commit
This commit is contained in:
9
src/store/cookie/client-cookie.ts
Normal file
9
src/store/cookie/client-cookie.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { createCookieStore, type CookieSetOptions } from "@kri/common/browser";
|
||||
import type { CookieKey } from "./cookie-keys";
|
||||
|
||||
export type { CookieSetOptions };
|
||||
export const cookieStore = createCookieStore<CookieKey>({
|
||||
defaults: { days: 365, path: "/", secure: false, sameSite: "Lax" },
|
||||
});
|
||||
5
src/store/cookie/cookie-keys.ts
Normal file
5
src/store/cookie/cookie-keys.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const CookieKeys = {
|
||||
AuthToken: "kri_authToken",
|
||||
} as const;
|
||||
|
||||
export type CookieKey = (typeof CookieKeys)[keyof typeof CookieKeys];
|
||||
2
src/store/jotai/auth.ts
Normal file
2
src/store/jotai/auth.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
"use client";
|
||||
export { authStateAtom, type AuthState } from "@/hooks/useAuth";
|
||||
1
src/store/jotai/dialog.ts
Normal file
1
src/store/jotai/dialog.ts
Normal file
@@ -0,0 +1 @@
|
||||
export type DialogId = "exampleDialog";
|
||||
8
src/store/jotai/loading.ts
Normal file
8
src/store/jotai/loading.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
"use client";
|
||||
|
||||
import { atom } from "jotai";
|
||||
import { isLoadingAtom } from "@/hooks/useLoading";
|
||||
|
||||
export const manualLoadingAtom = isLoadingAtom;
|
||||
export const queryLoadingAtom = atom(false);
|
||||
export const loadingAtom = atom((get) => get(isLoadingAtom) || get(queryLoadingAtom));
|
||||
27
src/store/storage/secure-storage.ts
Normal file
27
src/store/storage/secure-storage.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import { createJsonStorage, type JsonStorageTransform } from "@kri/common/browser";
|
||||
import { clientEnv } from "@/lib/env.client";
|
||||
import { Security } from "@/lib/security";
|
||||
|
||||
const securityTransform: JsonStorageTransform = {
|
||||
encode: (value) => Security.encryptBase64(value),
|
||||
decode: (value) => Security.decryptBase64(value),
|
||||
};
|
||||
|
||||
const options = (storage: "local" | "session") => ({
|
||||
storage,
|
||||
fallbackToPlainJson: true,
|
||||
...(clientEnv.ENV === "prod" ? { transform: securityTransform } : {}),
|
||||
} as const);
|
||||
|
||||
const local = createJsonStorage(options("local"));
|
||||
const session = createJsonStorage(options("session"));
|
||||
export const setLocalStorage = local.set;
|
||||
export const getLocalStorage = local.get;
|
||||
export const removeLocalStorage = local.remove;
|
||||
export const clearLocalStorage = local.clear;
|
||||
export const setSessionStorage = session.set;
|
||||
export const getSessionStorage = session.get;
|
||||
export const removeSessionStorage = session.remove;
|
||||
export const clearSessionStorage = session.clear;
|
||||
8
src/store/storage/storage-keys.ts
Normal file
8
src/store/storage/storage-keys.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export const StorageKeys = {
|
||||
AuthState: "kri:authState",
|
||||
} as const;
|
||||
|
||||
export type StorageKey = (typeof StorageKeys)[keyof typeof StorageKeys];
|
||||
export const StorageType: Record<StorageKey, "local" | "session"> = {
|
||||
[StorageKeys.AuthState]: "local",
|
||||
};
|
||||
Reference in New Issue
Block a user