jadjoubran / laravel-angular

(deprecated) Laravel & Angular package
https://laravel-angular.io
MIT License
179 stars 25 forks source link

Session store not set on request when trying to login #20

Open micobarac opened 5 years ago

micobarac commented 5 years ago

These are my API routes:

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::post('login', 'Auth\LoginController@login');

Route::group(['middleware' => 'auth:api'], function () {
    Route::get('logout', 'Auth\LoginController@logout');

    Route::get('posts', 'PostsController@index');
});

I installed Laravel Angular and Tymon JWT according to your docs, but when I try to call login method through the Postman on http://localhost:8000/api/login, I get Session store not set on request error. The only thing I added to these components is Barryvdh CORS component.

It looks like Laravel is expecting some kind of CSRF token, but I cannot give it one. I'm not sure about this, anyway.

micobarac commented 5 years ago

Btw, I don't understand how your Laravel Angular component works on integration between Laravel and Angular. The docs show the way to install it, but there isn't any info on the mechanism it provides in details. Can you please explain this? Thanks.

jadjoubran commented 5 years ago

Hey @micobarac Thanks for opening an issue! You're right, there's only the "Laravel side of things" but not the Angular one. Let's see how we solve this issue here and if it turns out helpful, maybe I (or we) can work on an angular-laravel package that accompanies this PHP package.

I think you need to move the login into the auth middleware (not auth:api yet because it's not authenticated yet) That's because you don't need CSRF tokens when workign with APIs Keep me posted!

OzzyTheGiant commented 5 years ago

That's because you don't need CSRF tokens when working with APIs

Not unless the API in question is actually part of the back-end of a Single Page Application that uses sessions to authenticate each request while logged in.