1
votes

I have generated some demo user through seeders. I can login those user by oauth/token. But when I create new user. I can't login anymore. It always giving me 401 unauthorized 'invalid credentials'. I have done all research. I am testing through POSTMAN I am totally clueless. This is my register method:

$user = new User;
$user->name = ucfirst($request['name']);
$user->email = $request['email'];
$user->password = bcrypt($request['password']);
$user->save();
return response()->json('success'); 

This is the method executes when posting in oauth/token route provided by Laravel passport:

public function issueToken(ServerRequestInterface $request)
    {
        return $this->withErrorHandling(function () use ($request) {
            return $this->convertResponse(
                $this->server->respondToAccessTokenRequest($request, new Psr7Response)
            );
        });
    } 

Pls, help me!!

1
I assume you have checked the database to make sure the user is being registered and stored right?Option
yes ofcourse ! i have done all possible things but no clue still.WahidSherief
can you show your authorization code?JorenV
well for authorization i am using laravel/passport oauth/token route which basically generates api. I have wrote nothing for this. I edited my question with the method it execute upon oauth/token route call. u can have a lookWahidSherief

1 Answers

0
votes

Ok finally i have figured out why was having this issue. I have method in User.php

public function setPasswordAttribute($password)
{   
    $this->attributes['password'] = bcrypt($password);
}

which is by default encrypting my password field.

But I forgot about it and was doing encryption again when saving password on database

$user->password = bcrypt($request['password']);

So it is encrypting twice. Hence i was not able to match the credentials. Totally my bad.