Something went wrong. Try again.
A simple to-do app focused on tasks that can be completed within a specific time span. taskline.tobinio.dev
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233let tokenPromise: Promise<string | null> | null = null;
export function useAuthToken() { const tokenData = useState<string | null>("auth-token", () => null);
async function getToken() { if (tokenData.value) return tokenData.value;
if (!tokenPromise) { const fetch = useRequestFetch();
tokenPromise = fetch<{ token: string }>("/api/auth/token") .then((data) => { tokenData.value = data.token; return tokenData.value; }) .catch(() => { tokenData.value = null; return null; }) .finally(() => { tokenPromise = null; }); }
return tokenPromise; }
return { getToken, };}