Is there any way to use in laravel jwt-auth the authentication using username instead an email?
public function authenticate(Request $request)
{
$credentials = $request->only('email', 'password');
try {
// verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong
return response()->json(['error' => 'could_not_create_token'], 500);
}
// if no errors are encountered we can return a JWT
return response()->json(compact('token'));
}
Something like this
$credentials = $request->only('username', 'password');
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1LJUmNo
via IFTTT
Yes, you can grab some user on the base of custom params and then authenticate it.
RépondreSupprimer// grab some user
$user = User::first();
$token = JWTAuth::fromUser($user);