Support the ongoing development of Laravel.io →
posted 6 years ago
Session
Last updated 6 months ago.
0

I suggest to you to use a token and don't rely on session if you working with Angular.

Simple reason: Just imagine that session timeouts and you still pushing data from Angular Next level reason: As soon as you thinking of API calls ( REST ) you need to try to avoid session dependency.

If you put Bearer token into your request header it is much more nicer - and soon - simpler.

https://tools.ietf.org/html/rfc6750

0

Hi @tothsanka, I'm aware of your suggestion but my usage of session is not related to authentication.

The real problem is that I'm working with Facebook login in order to get an authorization token from Facebook.

I'm using this library: https://github.com/SammyK/LaravelFacebookSdk

Debugging the app I realized that the session wasn't persisted.

What I explained was the isolated problem, which is the session wasn't persisted when the laravel resource is called through AngularJS.

So any other suggestion regarding my issue?

Thanks in advance!

0

Try the following in your config file, add this :

App.config(['$httpProvider', function ($httpProvider) { $httpProvider.defaults.withCredentials = true; }])

I am thinking maybe angular is not sending the headers needed for Laravel to identify your session...

0

I understand that. Once I got similar issue and that case I pushed FB accessToken to server and asked SDK to deliver the user. I deleted that build from github, but it was handy and no local copy.

0

Hi @mrj936, I tried your suggestion but it doesn't work.

I've printed the session ID in the ajax call and the directly browser call and I get the same session ID, so the session is the same. But I don't get the session value.

To write a session value I use Session::put('var_name', var_value'); and for retrieve it: Session::get('var_name');

Is that ok?

0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

hfuccillo hfuccillo Joined 20 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.