mardi 27 mars 2018

Why I cannot set Config for jwt-auth providers using PHP Laravel 5.6?

I have two different models and need to authenticate each.

The first model is working fine which is predefined in the config/auth.php but when I try to set config for second model, it doesn't work.

I have the following code for second model:

public function loginParent(Request $request)
{

    Config::set('auth.providers.users.model', ChildrenParent::class);

    $credentials = $request->only('email', 'password');

    try {
        if (!$token = JWTAuth::attempt($credentials)) {
            return response()->json(['error' => 'invalid_credentials'], 401);
        }
    } catch (JWTException $e) {
        return response()->json(['error' => 'could_not_create_token'], 500);
    }
    return response()->json(compact('token'));
}

And the code for auth.php:

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\Employee::class,
    ],
],

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],
],

I tested, and it works fine if I change the model name in the auth.php.

Error: It always return 'invalid credentials'.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2pJz9ft
via IFTTT

Aucun commentaire:

Enregistrer un commentaire