首页 > 解决方案 > 如何在 JWT API - Laravel 5.8 上验证用户群?

问题描述

我在 Laravel 5.8 上使用 PHP 7.2。

我目前使用 Laravel 附带的身份验证提供程序来登录我的用户。

它当前检查配置的数据库中的电子邮件和密码是否匹配。

我做了这个

$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);
} 

我不能再这样做了,我必须调用一个返回令牌的 API。


只是为了澄清:

我的主要目标是调用 JWT API,并在收到 200 响应时让我的用户登录。

我的用户现在如何登录?

标签: phplaravellaravel-5jwtjwt-auth

解决方案


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

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


推荐阅读