New to Stytch/programming - Log Out functions

Hi, I’m having trouble getting the log out functionality to work on the Stytch backend API with magic links. Here’s part of what I have:

Backend endpoint:"/logout", async (req, res) => {
  const { session_token } = req.body;
  await client.sessions.revoke({ session_token });

  const handleLogout = async () => {
    try {
      const cookie = new Cookies();
      const sessionToken = cookie.get('sessionToken').session_token;

      const response = await'http://localhost:3002/logout', {
        session_token: sessionToken,
    } catch (err) {
      console.error('Error revoking session:', error);

But I keep getting the 400 error:

status_code: 400,
  request_id: 'request-id-test-b9a3b301-1344-48ae-8f41-34c7caee7dae',
  error_type: 'no_session_revoke_arguments',
  error_message: 'Please include a session_id, session_token, session_jwt, or a member_id (if the project is a B2B project). Exactly one of those values is required to revoke a session.',
  error_url: ''

Any help?

Hey Serge – thanks for posting!

It looks like your session_token value isn’t making it into your client.sessions.revoke request for some reason. Have you tried printing or inspecting your session_token value inside"/logout"... right before client.sessions.revoke is called? That might help narrow down what’s going wrong here.

Let me know how that goes!