Files
Folo/apps/ssr/client/query/auth.ts
T
Innei 2314b996d4 refactor: update auth import paths to use @client/lib/auth
This commit updates import paths for auth-related functions across multiple files, changing them from `~/lib/auth` to `@client/lib/auth`. The changes ensure consistent and correct import paths for authentication functions in the client application.

Signed-off-by: Innei <tukon479@gmail.com>
2025-03-04 19:34:11 +08:00

39 lines
952 B
TypeScript

import { getSession } from "@client/lib/auth"
import type { AuthSession } from "@follow/shared/hono"
import { useQuery } from "@tanstack/react-query"
import type { FetchError } from "ofetch"
export const useSession = (options?: { enabled?: boolean }) => {
const { data, isLoading, ...rest } = useQuery({
queryKey: ["auth", "session"],
queryFn: () => getSession(),
retry(failureCount, error) {
const fetchError = error as FetchError
if (fetchError.statusCode === undefined) {
return false
}
return !!(3 - failureCount)
},
enabled: options?.enabled ?? true,
meta: {
persist: true,
},
})
const { error } = rest
const fetchError = error as FetchError
return {
session: data?.data as AuthSession,
...rest,
status: isLoading
? "loading"
: data?.data
? "authenticated"
: fetchError
? "error"
: "unauthenticated",
}
}