@jeske Laravel Fortify and Laravel Sanctum are two separate packages that handle authentication in different ways. Fortify is designed to work with traditional, session-based authentication, while Sanctum is designed to work with API token-based authentication.
To integrate the two packages, you would need to modify the login process to handle both the traditional session-based authentication (via Fortify) and the API token-based authentication (via Sanctum) simultaneously.
Here's one way you could do this:
- In your login controller, use Fortify's
loginmethod to handle the session-based authentication. - In your login controller, after the user is authenticated, use Sanctum's
createTokenmethod to generate a token for the user. - Return both the token and the session-based authentication information to the client.
- On the client, store the token in local storage or a cookie, and use it for all API requests.
- On the client, use the session-based authentication information to authenticate the user for non-API requests.
You would also need to modify your middleware to check for the token on API requests and also check for session-based authentication on web requests
It's also worth noting that Fortify and Sanctum are both built on top of Laravel's built-in authentication features, so you could also customize the authentication guard and provider to handle the authentication process in a way that allows you to use both Sanctum and Fortify together.