When user presses the login button, I redirect to usercontroller.php and obtain jwt token from API.
$result = $this->obtainAccessToken($request->email, $request->password);
then I put the JWT token and user info to session.
Session::put('user', $result);
then redirect user to home page.
return redirect(route('home'));
Everything is ok.
I can access that token and user info in view (blade) pages using
Session::get('user');
But sometimes I need to request jQuery ajax to server. But I dont have token info in my js files. How can I send that token info which is stored in session to js files?
Also I tried to store that info in Cookie like;
Cookie::queue('user', $result, 10);
But I couldn't access in jQuery using;
$.Cookie('user');
it returns undefined.
UPDATE
I found a way something like this;
<meta name="token" content="{{ Session::get('user')->token }} />
and access using jQuery
$('meta[name=token]').attr('content);
but is it safe method?