Files
reflector/www/app/lib/useSessionAccessToken.ts
Mathieu Virbel 790b7992bb fix: remove infinite re-render loop in useSessionAccessToken
The hook was maintaining redundant local state that caused re-renders
on every update, which triggered NextAuth to continuously refetch the
session, resulting in hundreds of POST requests to /api/auth/session.

Simplified the hook to directly return session values without
unnecessary state duplication.
2025-08-29 18:52:13 -06:00

16 lines
447 B
TypeScript

"use client";
import { useSession as useNextAuthSession } from "next-auth/react";
import { CustomSession } from "./types";
export default function useSessionAccessToken() {
const { data: session } = useNextAuthSession();
const customSession = session as CustomSession;
return {
accessToken: customSession?.accessToken ?? null,
accessTokenExpires: customSession?.accessTokenExpires ?? null,
error: customSession?.error,
};
}