Hi, I've been trying to generate a token based on a given data, like the given code below
`class UserController extends Controller
{
/**
* route: /api/users
*/
public function index()
{
$payload = JWTFactory::sub(123)->aud('foo')->foo(['bar' => 'baz'])->make();
$token = JWTAuth::encode($payload);
return response()->json(compact('token'));
}`
however im getting an empty output like this:
{
"token": []
}
seems like its not allowing some characters on a json payload, any help would be apreciated thanks.
compact('payload') would generate a result in the form 'payload' => $payload; there would be no key named "token". Are you sure this is the code you're running?
seems like its not allowing some characters on a json payload
Why have you come to this conclusion? Are there some characters that work and some that don't?
Thanks, yeah, sorry I mean compact ('token') , edited now, tried on var dumping the $token and im getting a random string as expected.
Got it, im plugging a Tymon\JWTAuth\Token object directly to an array value, it should be this
way:
$token = JWTAuth::encode($payload)->get();
to return a token as a string.
this should be specified in the wiki as well
particularly here -> Creating a Token based on anything you like
Yup same issue, my token was empty without get()
Most helpful comment
this should be specified in the wiki as well
particularly here -> Creating a Token based on anything you like