mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 12:50:05 +01:00
18 lines
465 B
TypeScript
18 lines
465 B
TypeScript
import { useSyncExternalStore } from "react"
|
|
import { authStore, type TokenPair } from "@/auth/store.ts"
|
|
|
|
export const useAuth = () => {
|
|
const tokens = useSyncExternalStore<TokenPair | null>(
|
|
(cb) => authStore.subscribe(cb),
|
|
() => authStore.get(),
|
|
() => authStore.get() // server snapshot (SSR)
|
|
)
|
|
|
|
return {
|
|
tokens,
|
|
authed: !!tokens?.access_token,
|
|
isExpired: authStore.isExpired(),
|
|
willExpireSoon: authStore.willExpireSoon(),
|
|
}
|
|
}
|