简体   繁体   中英

How to authenticate user base on JWT API - Laravel 5.8?

I'm using PHP 7.2 on Laravel 5.8.

I current use Auth provider that came with Laravel to log my users in.

It currently check if the email, and password match in the database configured.

I did this

$dbAuth = Auth::attempt(array(
    'email' => $email,
    'password' => $password
));

if ($dbAuth) {

    return Redirect::to('/dashboard')->with('success', 'You have been successfully logged in.');

} else {
    return Redirect::to('/')->with('error', 'Username/Password Wrong')->with('email', $email)->withErrors($validator);
} 

I can't do that anymore, I have to talk to call an API that return a token.


Just to clarify :

My main goal is to call JWT API, and logged my user in if I got the 200 response.

How do log my users in now?

I would recommend you use this package for JWT auth, it has a good documentation as well.

https://github.com/tymondesigns/jwt-auth

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM