我最近用完了project in git 我使用了JWT Auth,由于某种原因,令牌没有保存,因此-我总是被踢到主页。
以下是我克隆它时所执行的步骤:
用户似乎无法在中间件中进行身份验证-我在用户个人资料页面的构造函数中添加了一个断点,看来问题出在那儿
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Tymon\JWTAuth\Facades\JWTAuth;
class UserProfileController extends Controller
{
public function __construct()
{
$this->middleware('jwt.auth'); // that's what make the problem
}
public function addNewFriend(Request $request)
{
$newFriendId = $request->all()[0];
$userId = $request->user()->id;
User::addFriend($userId, $newFriendId);
}
public function getAuthenticatedUser()
{
try {
if (! $user = JWTAuth::parseToken()->authenticate()) {
return redirect('/login')->with('status', 'user not found!');
}
} catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
return response()->json(['token expired'], $e->getStatusCode());
} catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
return response()->json(['token Invalid'], $e->getStatusCode());
} catch (Tymon\JWTAuth\Exceptions\JWTExecption $e) {
return response()->json(['token absent'], $e->getStatusCode());
}
$loggedUserData = self::setLoggedUserData($user);
return response()->json(compact('loggedUserData'));
}
public function setLoggedUserData($loggedUser)
{
$userId = Auth::id();
$site_all_users = User::getAllUsersWithFriendsIndication($userId);
$userHobbies = User::getUserHobbies($userId);
$potentialFriends = User::getPotentialFriends($userId);
$friendsBirthDays = User::getFriendsBirthDaysDates($userId);
$usersFriends = User::getAllUserFriends($userId);
$upComingBirthDays = User::getUpComingBirthDays();
$loggedUser['userHobbies'] = json_encode($userHobbies);
$loggedUser['potentialFriends'] = json_encode($potentialFriends);
$loggedUser['friendsBirthDays'] = json_encode($friendsBirthDays);
$loggedUser['site_all_users'] = json_encode($site_all_users);
$loggedUser['usersFriends'] = json_encode($usersFriends);
$loggedUser['upComingBirthDays'] = json_encode($upComingBirthDays);
return $loggedUser;
}
}
答案 0 :(得分:0)
知道了-这是项目批处理命令的错误顺序,这是正确的顺序:
运行 作曲家更新 运行npm install
运行 PHP的工匠键:生成 php artisan vendor:publish --provider =“ Tymon \ JWTAuth \ Providers \ LaravelServiceProvider” php artisan jwt:secret