Trying to revoke a session server-side.

Hello! I have been trying to revoke a session server-side, I figured I could try to use:
const result = await auth.api.revokeSession({
method: "POST",
body: {
token: userToken
},
headers: {},
asResponse: true
})
const result = await auth.api.revokeSession({
method: "POST",
body: {
token: userToken
},
headers: {},
asResponse: true
})
As the function signature suggests, however when I do this I always get
Response (0 KB) {
ok: false,
url: "",
status: 401,
statusText: "UNAUTHORIZED",
headers: Headers {
"content-type": "application/json",
},
redirected: false,
bodyUsed: false
}
Response (0 KB) {
ok: false,
url: "",
status: 401,
statusText: "UNAUTHORIZED",
headers: Headers {
"content-type": "application/json",
},
redirected: false,
bodyUsed: false
}
And userToken is provided to me in a request (Using Bun's HTTP-Server) as the header User-Token: <token>. I also tried setting
"Cookie": `better_auth.session_token=${userToken}`
"Cookie": `better_auth.session_token=${userToken}`
as a header, but it doesn't seem to change anything.
Solution:
If anyone else needs this: - Install the bearer plugin - Create a headers object - Set Authorization: Bearer <token>...
Jump to solution
1 Reply
Solution
Ike
Ike4mo ago
If anyone else needs this: - Install the bearer plugin - Create a headers object - Set Authorization: Bearer <token> - Call
const result = await auth.api.signOut({
headers: headers,
asResponse: true
})
const result = await auth.api.signOut({
headers: headers,
asResponse: true
})
And you're done! If you want you can also pass in the request's headers directly :P

Did you find this page helpful?