404labfr / 404labfr/laravel-impersonate

Using Laravel Fortify / Sanctum impersonate returns false

Đang mở
#183 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
next version
Ngôn ngữ chính
PHP
Star
2.3k
Fork
235
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hi, I'm using Laravel 10 as a backend to a Nuxt JS front-end. I've installed the package, when I send a request to login to my endpoint's function attached, my `$impersonate` variable returns false, why aren't I being logged in?

```php
/**
* Log in as a user
*
* @return \Illuminate\Http\Response
*/
public function loginAsUser(User $user, Request $request)
{
$validator = Validator::make($request->all(), [
'id' => 'required|numeric|exists:users,id'
]);

if ($validator->fails()) {
return new ApiValidationErrorResponse($validator->messages());
}

$user = User::with('company')->find(Auth::id());

// must be on the default company
if (!isset($user->company) || (isset($user->company) && !$user->company->is_system_default)) {
return new ApiSuccessResponse(null, [
'message' => "You cannot log in as other users unless on the system default company.",
], 400);
}

// double check that this user is a super admin
if (!$user->hasRole('super_admin')) {
return new ApiSuccessResponse(null, [
'message' => "You are not allowed to log in as this user.",
], 400);
}

// get the user to login as
$newUser = User::find($request->input('id'));

$impersonate = $user->impersonate($newUser);

return new ApiSuccessResponse($impersonate, [
'newuser' => $newUser,
'newuser2' => Auth::user()
]);
}
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.