fix(auth): preserve Sanctum token prefix for lookups

Sanctum uses the numeric prefix (e.g. "69|...") in plaintext tokens
to index and look up tokens. Stripping this prefix breaks token
resolution.
This commit is contained in:
Andras Bacsai 2026-03-01 14:08:29 +01:00
parent ad433a0798
commit b38ce26e34

View file

@ -4,7 +4,6 @@
use App\Models\InstanceSettings;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Str;
use Laravel\Sanctum\PersonalAccessToken;
use Livewire\Component;
@ -122,7 +121,8 @@ public function addNewToken()
]);
$token = auth()->user()->createToken($this->description, array_values($this->permissions));
$this->getTokens();
session()->flash('token', Str::after($token->plainTextToken, '|'));
// Do NOT strip the numeric prefix (e.g. "69|...") — Sanctum uses it to index and look up tokens.
session()->flash('token', $token->plainTextToken);
} catch (\Exception $e) {
return handleError($e, $this);
}