Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MohamedKamal's avatar

Logout Api

Does api need logout endpoint? Or it handled in frontend?

0 likes
4 replies
LaryAI's avatar
Level 58

It depends on the type of authentication you are using. If you are using token-based authentication, then you will need an endpoint to invalidate the token. This can be done by sending a DELETE request to the logout endpoint.

If you are using session-based authentication, then you can handle the logout in the frontend. You can clear the session data from the browser and redirect the user to the login page.

// Token-based authentication
axios.delete('/logout')
  .then(response => {
    // handle success
  })
  .catch(error => {
    // handle error
  });

// Session-based authentication
localStorage.clear();
window.location.href = '/login';
jlrdw's avatar

Each chapter whether Sanctum or Passport will cover how to revoke a token.

MohamedKamal's avatar

@jlrdw i know how to do it, I mean do I need it in api? Should I make logout endpoint?

Please or to participate in this conversation.