https://github.com/tymondesigns/jwt-auth is working perfectly for authenticating users for defualt guard but I want to login users from another table (auth:guard)
Here is config/auth.php:
'defaults' => [
'guard' => 'user',
'passwords' => 'users',
],
'guards' => [
'user' => [
'driver' => 'jwt',
'provider' => 'users',
],
'student' => [
'driver' => 'jwt',
'provider' => 'students',
],
'father' => [
'driver' => 'jwt',
'provider' => 'fathers',
],
'mother' => [
'driver' => 'jwt',
'provider' => 'mothers',
],
],
As I mentioned, jwt authentication is working for 'guard' => 'user' as it is default one but I want to authenticate student using 'guard' => 'student' without changing default guard.
Here is my login function:
public function login(Request $request){
$credentials = $request->only('email', 'password');
$jwt = '';
try {
if (!$jwt = JWTAuth::attempt($credentials)) {
return response()->json([
'response' => 'error',
'message' => 'invalid_credentials',
], 401);
}
} catch (JWTAuthException $e) {
return response()->json([
'response' => 'error',
'message' => 'failed_to_create_token',
], 500);
}
return response()->json([
'message' => 'success',
'result' => ['token' => $jwt]
]);
}
For better understanding, I have followed all steps showed in documentation to install tymon/jwt-auth version dev-develop. Any help is highly appreciated