从git克隆我的Laravel项目后无法登录

时间:2019-08-18 07:21:53

标签: laravel jwt-auth

我最近用完了project in git 我使用了JWT Auth,由于某种原因,令牌没有保存,因此-我总是被踢到主页。

以下是我克隆它时所执行的步骤:

  1. https://github.com/roybarak80/Laravel-Social-App.git克隆
  2. 创建数据库
  3. 从根文件夹导入DB.sql
  4. 使用您的数据库凭据更新.env文件(将.env.samlpe重命名为.env)
  5. 运行作曲家更新
  6. 运行npm install
  7. 运行php artisan key:generate
  8. 运行php artisan config:cache
  9. 运行php artisan供应商:发布--provider =“ Tymon \ JWTAuth \ Providers \ LaravelServiceProvider”

用户似乎无法在中间件中进行身份验证-我在用户个人资料页面的构造函数中添加了一个断点,看来问题出在那儿

<?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;
}


}

1 个答案:

答案 0 :(得分:0)

知道了-这是项目批处理命令的错误顺序,这是正确的顺序:

  1. git clone https://github.com/roybarak80/Laravel-Social-App.git
  2. 创建数据库
  3. 从根文件夹导入DB.sql
  4. 使用您的数据库凭据更新.env文件(将.env.samlpe重命名为.env)
  5. 运行 作曲家更新 运行npm install

  6. 运行 PHP的工匠键:生成 php artisan vendor:publish --provider =“ Tymon \ JWTAuth \ Providers \ LaravelServiceProvider” php artisan jwt:secret