Middleware signout

how can i signout a user session from nextjs middleware. the authclient is not working there because its a client component. using the auth directly
auth.api.signout({headers: request.headers})
auth.api.signout({headers: request.headers})
doesnt work as well
2 Replies
bekacru
bekacru5mo ago
create a new vanilla client and call authClient.signOut
import { createAuthClient } from "better-auth/client";

const client = createAuthClient();

await client.signOut({
fetchOptions: {
headers: request.headers
}
})
import { createAuthClient } from "better-auth/client";

const client = createAuthClient();

await client.signOut({
fetchOptions: {
headers: request.headers
}
})
but may I ask why you would want to do that?
kingkyle
kingkyleOP5mo ago
im checking the session for a user role. if it not the role then signout the user Thank you it worked

Did you find this page helpful?