feat: add fetch cache no-store and header cache-control no-store

This commit is contained in:
DIYgod 2025-07-11 18:19:08 +08:00
parent 6fc431c112
commit 093e47cb0a
No known key found for this signature in database
13 changed files with 20 additions and 32 deletions

View File

@ -16,6 +16,7 @@ const apiFetch = ofetch.create({
credentials: "include",
signal: abortController.signal,
retry: false,
cache: "no-store",
onRequest({ request }) {
logger.info(`API Request: ${request.toString()}`)
},

View File

@ -20,6 +20,7 @@ export const apiFetch = ofetch.create({
baseURL: env.VITE_API_URL,
credentials: "include",
retry: false,
cache: "no-store",
onRequest: ({ options }) => {
const header = new Headers(options.headers)
@ -85,10 +86,7 @@ export const apiFetch = ofetch.create({
export const apiClient = hc<AppType>(env.VITE_API_URL, {
fetch: async (input, options = {}) =>
apiFetch(input.toString(), {
...options,
cache: "no-store",
}).catch((err) => {
apiFetch(input.toString(), options).catch((err) => {
if (err instanceof FetchError && !err.response) {
setApiStatus(NetworkStatus.OFFLINE)
}

View File

@ -19,6 +19,7 @@ export const apiFetch = ofetch.create({
retry: false,
credentials: "omit",
baseURL: proxyEnv.API_URL,
cache: "no-store",
onRequest: async (ctx) => {
const { options, request } = ctx
if (__DEV__) {
@ -78,10 +79,7 @@ export const apiFetch = ofetch.create({
export const apiClient = hc<AppType>(proxyEnv.API_URL, {
fetch: async (input: any, options = {}) =>
apiFetch(input.toString(), {
...options,
cache: "no-store",
}).catch((err) => {
apiFetch(input.toString(), options).catch((err) => {
throw err
}),
async headers() {

View File

@ -49,6 +49,7 @@ const plugins = [
export const authClient = createAuthClient({
baseURL: `${proxyEnv.API_URL}/better-auth`,
fetchOptions: {
cache: "no-store",
// Learn more: https://better-fetch.vercel.app/docs/hooks
onRequest: async (ctx) => {
const headers = createMobileAPIHeaders({

View File

@ -9,6 +9,7 @@ import PKG from "../../../desktop/package.json"
const apiFetch = ofetch.create({
credentials: "include",
retry: false,
cache: "no-store",
onRequest: ({ options }) => {
const header = new Headers(options.headers)

View File

@ -11,6 +11,7 @@ const auth = new Auth({
webURL: env.VITE_WEB_URL,
fetchOptions: {
headers,
cache: "no-store",
},
})

View File

@ -33,6 +33,7 @@ export const createApiFetch = () => {
return ofetch.create({
credentials: "include",
retry: false,
cache: "no-store",
onRequest(context) {
if (__DEV__) console.info(`request: ${context.request}`)

View File

@ -40,7 +40,6 @@
"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,7 +4,6 @@ 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 = [
@ -58,21 +57,13 @@ export class Auth {
plugins: baseAuthPlugins,
fetchOptions: {
...this.options.fetchOptions,
cache: "no-store",
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,7 +124,6 @@
"@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,7 +3,6 @@ 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"
@ -67,11 +66,9 @@ class UserSyncService {
})
async whoami() {
const res = (await (apiClient()["better-auth"] as any)["get-session"].$get({
query: {
v: nanoid(8),
},
})) as AuthSession | null
const res = (await (apiClient()["better-auth"] as any)[
"get-session"
].$get()) as AuthSession | null
if (res) {
const user = honoMorph.toUser(res.user, true)
immerSet((state) => {

View File

@ -50,6 +50,10 @@ export const createBuildSafeHeaders =
return headers
}
const commonHeaders = {
"Cache-Control": "no-store",
}
enum DesktopPlatform {
Desktop = "desktop",
DesktopWeb = "desktop/web",
@ -92,6 +96,7 @@ export const createDesktopAPIHeaders = ({ version }: { version: string }) => {
}
return {
...commonHeaders,
...(platform ? { "X-App-Platform": platform } : {}),
"X-App-Name": "Folo Web",
"X-App-Version": version,
@ -105,6 +110,7 @@ enum SSRPlatform {
export const createSSRAPIHeaders = ({ version }: { version: string }) => {
return {
...commonHeaders,
"X-App-Platform": SSRPlatform.SSR,
"X-App-Name": "Folo SSR",
"X-App-Version": version,
@ -148,6 +154,7 @@ export const createMobileAPIHeaders = ({
}
return {
...commonHeaders,
...(platform ? { "X-App-Platform": platform } : {}),
"X-App-Name": "Folo Mobile",
"X-App-Version": version,

View File

@ -1697,9 +1697,6 @@ 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)
@ -1742,9 +1739,6 @@ 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