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);
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);
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 131I don麓t have a "password" column in my user麓s table.