vendredi 23 août 2019

How to log user in via API - Laravel 5.8?

I'm using Laravel 5.8, with PHP 7.2.

I need to adjust the way I did the Authentication.

before

I used to log my users in via my local database from users table.

If the email+password match, I log them in.

$email = strtolower(Input::get('email'));
$password = Input::get('password');

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

if ($dbAuth) {
    Session::put('user', Auth::user());
    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);
}

now

Now I need to call /login API, that will return a token. I need to store that token into the local storage on my browser.

I need to make sure my Auth::user() will work base on change.

How do I start ?

Can someone please shed some lights ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire