diff --git a/apps/console/src/app/providers.tsx b/apps/console/src/app/providers.tsx index b6422a35..87be86b7 100644 --- a/apps/console/src/app/providers.tsx +++ b/apps/console/src/app/providers.tsx @@ -16,14 +16,17 @@ const Providers = ({ children }: ProvidersProps) => { const { data: session, status } = useSession() const pathname = usePathname() const [client, setClient] = useState(null) + const [accessToken, setAccessToken] = useState(null) useEffect(() => { - if (status === 'authenticated') { + const tokenChanged = session?.user.accessToken && session?.user.accessToken !== accessToken + if (status === 'authenticated' && tokenChanged) { + setAccessToken(session?.user.accessToken) setClient(createClient(session)) } else if (status === 'unauthenticated' && pathname.endsWith('waitlist')) { setClient(createSubscriberClient()) } - }, [session, status, pathname]) + }, [session?.user.accessToken, status, pathname, accessToken]) if (status === 'loading' || (status === 'authenticated' && !client)) return null