GokuLess
GokuLess

Reputation: 9

PHP-JWT user in token

In my php api(framework lumen), I'm retrieving user data along with token. I want to put this user data into a hashed token.

My current code look like this:

    if (! $token = $this->jwt->attempt($request->only('email', 'password'))) {
        return response()->json(['user_not_found'], 404);
    }

    $user = $this->jwt->user();

    return response()->json(compact('token', 'user'));

Upvotes: 0

Views: 477

Answers (1)

Sibasankar Bhoi
Sibasankar Bhoi

Reputation: 589

You can use like this for hashing data

                   $key= "User access token";                  // create a key

                    $hash_data= array(
                    "email" => $email,
                    "password" => $password,
                );

               $access_token = JWT::encode($hash_data, $key);
               return response()->json(compact('token', 'access_token '));

In $access_token details will be in encrypt format, when you want only decode it

Upvotes: 1

Related Questions