Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JWT $request->user(guard) 运行一段时间后 获取值为null。已添加清理器。 #413

Open
pleaseyang opened this issue Aug 17, 2022 · 5 comments
Assignees
Labels
analyzing Analyzing this issue

Comments

@pleaseyang
Copy link

  1. Your software version (Screenshot of your startup)

    Software Version
    PHP 8.1.1
    Swoole 4.8.5
    Laravel/Lumen 9.23.0
    Laravels 3.7.33
  2. Detail description about this issue(error/log)

    laravels start 后,运行一段时间,接口请求时间 < 1s后。 $request->user(guard) 获取为 null

  3. Some reproducible code blocks and steps

1
2
3
4

@pleaseyang pleaseyang added the analyzing Analyzing this issue label Aug 17, 2022
@pleaseyang pleaseyang changed the title $request->user(guard) 运行一段时间后 获取值为null。已添加清理器。 JWT $request->user(guard) 运行一段时间后 获取值为null。已添加清理器。 Aug 17, 2022
@SVV-team
Copy link

SVV-team commented Oct 11, 2022

@hhxsv5

image

Same trouble without cleaners and with default guard (session)

Route::get('/user', function (\Illuminate\Http\Request $request) {
    return response()->json($request->user());
});

Returns user only for first request after start or reload

Route::get('/user', function (\Illuminate\Http\Request $request) {
    return response()->json(\Illuminate\Support\Facades\Auth::user());
});

Work correctly, but many packages and me too use User from request

@SVV-team
Copy link

SVV-team commented Oct 11, 2022

@hhxsv5 @pleaseyang
maybe trouble with request user resolver ?

Temp solution
Resolve user on each request (middleware)

$request->setUserResolver(
    fn() => \Illuminate\Support\Facades\Auth::user()
);

Something like this work good, but maybe its dangerous

@killjin
Copy link

killjin commented Nov 20, 2022

同问,还是不行

@uptonyuan
Copy link

uptonyuan commented Nov 20, 2022 via email

@killjin
Copy link

killjin commented Nov 20, 2022

auth:user 就没事,很奇怪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzing Analyzing this issue
Projects
None yet
Development

No branches or pull requests

5 participants