You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?phpnamespaceApp\Providers;
useApp\Models\User;
useIlluminate\Http\Request;
useIlluminate\Support\ServiceProvider;
useKnuckles\Camel\Extraction\ExtractedEndpointData;
useKnuckles\Scribe\Scribe;
classScribeServiceProviderextendsServiceProvider
{
publicfunctionboot()
{
if (class_exists(\Knuckles\Scribe\Scribe::class)) {
Scribe::beforeResponseCall(function (Request$request, ExtractedEndpointData$endpointData) {
// Get the current URL prefix$urlPrefix = $request->route()->getAction('prefix');
// Check the URL prefix and set the appropriate tokenif ($urlPrefix === 'admin') {
$token = User::where('type', 'admin')->first()->createToken('user')->plainTextToken;
} else {
$token = User::where('type', 'staff')->first()->createToken('user')->plainTextToken;
}
// Set the Authorization header$request->headers->set("Authorization", "Bearer $token");
// You also need to set the headers in $_SERVER$request->server->set("HTTP_AUTHORIZATION", "Bearer $token");
});
}
}
}
When I generate scribe, The request()->user() remains same in the endpoint. But I debugged the request headers The Authorization value is changed.
Scribe version
4.22.0
PHP version
8.2.4
Framework
Laravel
Framework version
10.14.1
Scribe config
What happened?
When I generate scribe, The
request()->user()
remains same in the endpoint. But I debugged the request headers The Authorization value is changed.NB: I am using
"laravel/sanctum": "^3.2",
in this case.Docs
The text was updated successfully, but these errors were encountered: