Jwt-auth: Token empty ?

Created on 30 Mar 2015  路  1Comment  路  Source: tymondesigns/jwt-auth

Hello,

I work on laravel 5.0. everything has been installed.. but when I try this example code.. I got empty token:

Controller:

$payload = app('tymon.jwt.payload.factory')->sub(123)->aud('foo')->foo(['bar' => 'baz'])->make();
$token = JWTAuth::encode($payload);
return Response::json(['success' => 1, 'message' => 'User is already register.', 'token' => $token], 200);

{"success":1,"message":"User is already register.","token":{}}

Any idea ?

Most helpful comment

what output do you get when you call dd($token); before returning the response ?

it should be an instance of Tymon\JWTAuth\Token, so it appears the __toString() method isn't firing in this case.

The following should work too

return Response::json(['token' => $token->get()]);

>All comments

what output do you get when you call dd($token); before returning the response ?

it should be an instance of Tymon\JWTAuth\Token, so it appears the __toString() method isn't firing in this case.

The following should work too

return Response::json(['token' => $token->get()]);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

CBR09 picture CBR09  路  3Comments

shah-newaz picture shah-newaz  路  3Comments

Rasoul-Karimi picture Rasoul-Karimi  路  3Comments

harveyslash picture harveyslash  路  3Comments

gamelife1314 picture gamelife1314  路  3Comments