Laravel 8 API REST Login

try this

 $data = [
        'email' => $request->email,
        'password' => $request->senha
    ];

as attempt() function look for email and password key

and change the database password

Or

you can manually login via auth()->login($user); function

$user = Usuario::where('email',$request->email)->first();
if(!$user){
    return response()->json(['error' => 'user not found.'], 401);
}

if (!Hash::check($request->senha,$user->senha)) {
    return response()->json(['error' => 'Unauthorised'], 401);
} else {
    auth()->login($user);
    $token = auth()->user()->createToken('LaravelAuthApp')->accessToken;
    return response()->json(['token' => $token], 200);
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top