Search code examples
laravellaravel-5stormpath

Laravel Stormpath not able to access User Object


I am using Laravel and Stormpath for User Management. I am able to register and login user successfully using AJAX.

After successful login only the url is returned to AJAX, but after login when I go to User specific pages I am not able to fetch User Data.

Registration and Login happens in RegisterController
User Pages are rendered using UserController

I've tried to get User data using

$user = app('stormpath.user');

in UserController, but when I do dd($user) null is returned.

How to persist or get User Data after successful login or sign-up in other Controllers?

Any help appreciated! Thanks in advance!


Solution

  • For the Stormpath Laravel integration, when you run AJAX calls, we do not set any cookies. We provide you with the JWT in the header response that you will need to look at and then store them youself. The JWT will then need to be attached to all other requests as a Bearer token which will allow you to use the `$user = app('stormpath.user') method to get the user information out of the JWT.