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

CItyTrader's avatar

Proper way to Authorize Laravel API using another frontend repository

I am using Sanctum for my APIs. I wonder whether sending bearer tokens on every authenticated request is good practice. Another option is to use sessions. If I were to use sessions, how would I implement it?

I would also appreciate if you could send me a link of a github repo implementing APIs for authentication PS: Please can anyone recommend the proper way of constructing API for authentication (login, register, logout)

0 likes
6 replies
martinbean's avatar

@CItyTrader You create an endpoint that returns tokens. You then use the returned token in subsequent requests to your API.

CItyTrader's avatar

@martinbean okay.. so I also discovered that this way is not secure and that we should use sessions with the tokens instead

martinbean's avatar

@CItyTrader Nope. RESTful APIs are typically stateless. You don’t use session-based authentication with them.

Please or to participate in this conversation.