1

I'm using Laravel 5.6 and Angular 6. My backend uses the standard session login precedure of Laravel, but there is a problem:

In Postman-Tests everything works - I get a Set-Cookie header from Laravel and I'm authenticated. If I open my API in the browser manually, I get the Set-Cookie header from Laravel, the cookie get stored in the browser and I'm authenticated - everything fine. But if I'm trying to access the API from my Angular-App, then the cookie is not set in the browser - although there is the correct Set-Cookie header.

Can anyone help me? The App is delivert from localhost:4200 and the API from localhost:4100. Is that a problem?

1

1 Answer 1

1

So this is probably do to your Angular app trying to access the cookie

All cookies created by the Laravel framework are encrypted and signed with an authentication code, meaning they will be considered invalid if they have been changed by the client.

Apparently using Angular with Laravel is not straightforward there is a guide to how to integrate it here:

https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps

These might be related to your problem:

https://github.com/angular/angular/issues/5254

angular 4 not send cookie to server

Laravel 5.5 and Angular 4 set cookie

Sign up to request clarification or add additional context in comments.

1 Comment

@SebastianS no problem, glad you found the solution! If you found my answer useful I would appreciate it if you upvoted it ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.