Next.js Discord

Discord Forum

Close Authjs session when external API responds 401

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
I'm using Nextjs 14 with Authjs beta. I log the user in with my custom BE, and store the token in the auth cookie. The issue comes when I want to sign-out the user whenever my BE responds with a 401,

I'm using react suspense, so if I want to call signOut() in my server actions, I get the Cookies can only be modified in a Server Action or Route Handler error. If I want to do a POST to the signout api, I get the Failed to parse URL from /api/auth/signout error.

I've also tried removing the cookies manually from the middleware without much results.

What's the recommended pattern for this kind of scenarios?

1 Reply

Spectacled bear
To follow, get the same issue.