chore: add nanoid package and update api-fetch to use no-store cache

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2025-07-11 15:52:37 +08:00
parent 6e73cbc75d
commit 46346679ab
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
7 changed files with 32 additions and 6 deletions

View File

@ -85,7 +85,10 @@ export const apiFetch = ofetch.create({
export const apiClient = hc<AppType>(env.VITE_API_URL, {
fetch: async (input, options = {}) =>
apiFetch(input.toString(), options).catch((err) => {
apiFetch(input.toString(), {
...options,
cache: "no-store",
}).catch((err) => {
if (err instanceof FetchError && !err.response) {
setApiStatus(NetworkStatus.OFFLINE)
}

View File

@ -78,7 +78,10 @@ export const apiFetch = ofetch.create({
export const apiClient = hc<AppType>(proxyEnv.API_URL, {
fetch: async (input: any, options = {}) =>
apiFetch(input.toString(), options).catch((err) => {
apiFetch(input.toString(), {
...options,
cache: "no-store",
}).catch((err) => {
throw err
}),
async headers() {

View File

@ -40,6 +40,7 @@
"better-auth": "1.2.9",
"drizzle-orm": "0.44.2",
"hono": "4.8.1",
"nanoid": "5.1.5",
"sonner": "2.0.6",
"stripe": "18.2.1",
"zod": "3.25.75"

View File

@ -4,6 +4,7 @@ import type { authPlugins } from "@follow/shared/hono"
import type { BetterAuthClientPlugin, BetterFetchOption } from "better-auth/client"
import { inferAdditionalFields, twoFactorClient } from "better-auth/client/plugins"
import { createAuthClient } from "better-auth/react"
import { nanoid } from "nanoid"
type AuthPlugin = (typeof authPlugins)[number]
export const baseAuthPlugins = [
@ -40,7 +41,6 @@ export type AuthClient<ExtraPlugins extends BetterAuthClientPlugin[] = []> = Ret
plugins: [...typeof baseAuthPlugins, ...ExtraPlugins]
}>
>
export type LoginRuntime = "browser" | "app"
export class Auth {
@ -58,12 +58,21 @@ export class Auth {
plugins: baseAuthPlugins,
fetchOptions: {
...this.options.fetchOptions,
onRequest: (context) => {
const referralCode = localStorage.getItem(getStorageNS("referral-code"))
if (referralCode) {
context.headers.set("folo-referral-code", referralCode)
}
if (context.query) {
context.query.v = nanoid(8)
} else {
context.query = {
v: nanoid(8),
}
}
this.options.fetchOptions?.onRequest?.(context)
return context

View File

@ -124,6 +124,7 @@
"@tanstack/react-query": "5.81.5",
"es-toolkit": "1.39.6",
"immer": "10.1.1",
"nanoid": "5.1.5",
"zustand": "5.0.6"
}
}

View File

@ -3,6 +3,7 @@ import type { UserSchema } from "@follow/database/schemas/types"
import { UserService } from "@follow/database/services/user"
import type { AuthSession } from "@follow/shared/hono"
import { create, indexedResolver, windowScheduler } from "@yornaath/batshit"
import { nanoid } from "nanoid"
import { apiClient, authClient } from "../context"
import type { Hydratable, Resetable } from "../internal/base"
@ -66,9 +67,11 @@ class UserSyncService {
})
async whoami() {
const res = (await (apiClient()["better-auth"] as any)[
"get-session"
].$get()) as AuthSession | null
const res = (await (apiClient()["better-auth"] as any)["get-session"].$get({
query: {
v: nanoid(8),
},
})) as AuthSession | null
if (res) {
const user = honoMorph.toUser(res.user, true)
immerSet((state) => {

View File

@ -1697,6 +1697,9 @@ importers:
hono:
specifier: 4.8.1
version: 4.8.1(patch_hash=5c74c2d2afaa5880c13d75458dd26c84da568851691b1fb6de6d877c29936d05)
nanoid:
specifier: 5.1.5
version: 5.1.5
sonner:
specifier: 2.0.6
version: 2.0.6(react-dom@19.0.0(react@19.0.0))(react@19.0.0)
@ -1739,6 +1742,9 @@ importers:
immer:
specifier: 10.1.1
version: 10.1.1(patch_hash=594c60b929bc0a3b56576f1a1787da1aec2a1fba51e3c21ec09c0ed38280af6c)
nanoid:
specifier: 5.1.5
version: 5.1.5
react:
specifier: 19.0.0
version: 19.0.0