Skip to content

useSession() not getting the updated session after logout and re login #10985

Discussion options

You must be logged in to vote

This is how I fixed the problem.

"use client";

import { Session } from "next-auth";
import { useSession } from "next-auth/react";
import { usePathname } from "next/navigation";
import { useEffect, useState } from "react";
import { authRoutes, publicRoutes } from "../routes";

export function useCustomSession() {
  const { data: lieSession, status, update } = useSession();
  const [truthSession, setUpdatedSession] = useState<Session | null>(null);

  const pathname = usePathname();

  //TODO: When logging out of your account, the session is not updated. An interesting fact is that the update occurs if you lose the focus of a browser tab and go back.
  useEffect(() => {
    update().then((…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sreenathkumar
Comment options

Answer selected by sreenathkumar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants