I am trying to generate token by verifying other fields and table rather than email and password of user table. I am using tymon jwt
library.
I have three fields that need to be verified to authenticate the user
table::where(["id"=>"1","mobile"=>"123","otp"=>"asdf"])->get();
So If I found the rows matching this condition in table then I want to authenticate the user and generate valid token with required claims.
What I have tried so far is :
//after check for three fields in DB. If row matches then, $id and $contact are variable from DB.
$customClaims = ['id' => $id, 'mobile' => $contact];
$payload = JWTFactory::make($customClaims);
When trying this I got JWT payload does not contain the required claims
.
So how to authenticate user with three field and generate valid token with required claims and $customClaims
.
Edited
public function verifyOTP(Request $request) {
$otp = $request->otp;
$schoolid = $request->schoolid;
$parent_contact = $request->contactNum;
$verifyOTP = OTP::where(['schoolid' => $schoolid, 'parent_numb' => $parent_contact, 'otp' => $otp])->get();
if ($verifyOTP) {
$customClaims = ['schoolid' => $schoolid, 'parent_numb' => $parent_contact];
$payload = JWTFactory::make($customClaims);
$token = JWTAuth::encode($payload);
return $token;
}
}