1 year ago

Two Laravel projects, API and Front (Web). How to "login" the user?

Posted 1 year ago by luddinus


I'm making an API, and I will use laravel for that. No problemo here.

I want to do TWO completely separate projects. I want to use simple blade pages in the front.

The main problem in my mind:

  • How to "login" a user?

I would have an endpoint like and when I login successfuly, a token will be return from the API (maybe some additional info like user name etc.)

The code in the FRONT project

// LoginController
public function store()
    // guzzle?
    $response = $http->post('', [
        'email' => '[email protected]',
        'password' => 'secret'

    // $response ---> ['token' => '...', 'user' => ['name' => '...', 'email' => '...']];

    // successfull
    // save the token in my DB? (Database of the Front End project, only to save the login users for example?)

    return redirect('dashboard');

Then I guess I would only have to do the requests with the saved token to the API

// ProfileController

public function update()
    // ...
    $response = $http->put('', [
        'token' => 'Saved-token-from-the-db',
        'some_data' => 'to update the profile'

    return back();

Is this a good way? Any ideas?


Please sign in or create an account to participate in this conversation.