I am a newbie with next-auth. my app still uses a frontend and backend separation, and I'm using CredentailProvider for login to obtain an access token from the backend server. when I fetch data from the API on the page and the API responds with a 401, I want to log out automatically. I noticed that signOut() is a client-side function, so I can't call signOut().
my sample code:
import auth from "@/lib/auth";
export default async function Page() {
const session = await auth();
const token = session?.accessToken;
const data = await getData({
token: token || "",
});
if (data.status === 401) {
// I want to logout here
return <p>Error: {data.error}</p>;
}
return (
<>{data.result}<>
);
}
I am using the Next-Auth v5
I can't call the signOut() function on SSR pages.