I am trying to use signOut that is exported from auth.ts and I get this message
[ Server ] Error: Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#options
7 messages · Page 1 of 1 (latest)
I am trying to use signOut that is exported from auth.ts and I get this message
[ Server ] Error: Cookies can only be modified in a Server Action or Route Handler. Read more: https://nextjs.org/docs/app/api-reference/functions/cookies#options
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
Your question currently does not have sufficient information for people to be able to help. Please add more information to help us help you, for example: relevant code snippets, a reproduction repository, and/or more detailed error messages. See more info on how to ask a good question in https://discord.com/channels/752553802359505017/1138338531983491154 and #welcome message.
cant really help much with ur question without u providing additional context, or code snippets
But it COULD be cuz u don't have a "use server" at the top of ur auth.ts file
Authentication libraries store the user token in the cookies, when you “signOut()” you’re effectively deleting the cookie via “cookies.delete()” which is an operation that can only happen in Server Actions or Route Handlers, that’s because these two have access to the requests headers.
Request Headers allow you to operate with cookies via the “HTTP Cookie” header, sending or modifying information on the client side (cookies are only stored on the client side)
Idk if I understood your question correctly, a little more context would help
In your case, I would create a folder with actions for auth: actions/auth
“use server”;
export async function signIn(){ … }
export async function signOut(){
….
signOut()
// or whatever way your
// auth library handles this
…
}