Laravel Breeze API login controller errors

1.2k views Asked by At

Trying out this 'new' Laravel Breeze API package, trying to combine it with Sanctum. Upon editing the code a bit I stumbled upon some weird error that I do not understand. When I try to authenticate with postman

 public function store(LoginRequest $request)
    {
        if($request->authenticate())
        {
            $token = $request->user()->createToken('AccessToken')->plainTextToken;
            return response(['AcessToken' => $token], 200);
        }
        else{
            return response(['Status' => 'Unsuccesful login']);
        }
    }

This is the AuthenticatedSessionController.php I tried to edit it to return an Access token if the login is successfull, and to send a 'Status' response if the login has failed, instead what I got is, upon sending valid login credentials, I get the ['Status' => 'Unsuccesful login'], and if the Login credentials are not valid, I get redirected to the root page "/", any ideas?

1

There are 1 answers

0
Barco On

From Laravel9 Sanctum is installed by default. This covers all api/ routes and is configured separately from Breeze. By default Sanctum will respond to cookie auth and accept/create tokens for token auth.

Routes in auth.php are used by Breeze. When you say postman I'm guessing you're hitting up an api route.

Here's the docs for Sanctum https://laravel.com/docs/9.x/sanctum