Jwt-auth: In the release "1.0.0-rc.1", how do i create a token by user?

Created on 31 Oct 2017  路  4Comments  路  Source: tymondesigns/jwt-auth

In the release "1.0.0-rc.1", how do i creating a token based on a user object?

I read the documentation http://jwt-auth.readthedocs.io/en/docs/quick-start/ and only explains the token generation using the attempt method.

$this->guard()->attempt($credentials)).

I need to validate my user like this:

public function login(Request $request)
{
$user = User::where('passwd', $request->pass)->get();
if ( $user  ){
// authenticates and returns the token
}
return response()->json(['error' => 'Unauthorized'], 401);

Most helpful comment

When i use the attempt() method i receive this error:

ErrorException: Undefined index: password in file /sysadm/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php on line 131

I don麓t have a "password" column in my user麓s table.

All 4 comments

protected function credentials(Request $request)
{
    return $request->only('passwd');
}

public function login(Request $request)
{
    $token = $this->guard()->attempt($this->credentials($request));
    if ($token) {
        // todo
    }
    return response()->json(['error' => 'Unauthorized'], 401);
}

When i use the attempt() method i receive this error:

ErrorException: Undefined index: password in file /sysadm/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php on line 131

I don麓t have a "password" column in my user麓s table.

You can do something like:

$token = auth()->login($user);
$token = auth()->byId($userId);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

lbottoni picture lbottoni  路  3Comments

therealmjk picture therealmjk  路  3Comments

heroghost picture heroghost  路  3Comments

mihailo-misic picture mihailo-misic  路  3Comments

harveyslash picture harveyslash  路  3Comments