Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rubendn's avatar

New Laravel Install w/ Jetstream/Livewire has Sanctum error

I set up a new project using the Laravel installer and chose Jetstream with Livewire.

When trying to register a new user, there is an error having to do with Sanctum. Sanctum was not installed during the installation process.

The errors are eliminated if I install Sanctum and remove the API trait from the User Model and change the guard in the config files.

My question is shouldn’t the install include Sanctum if it is required? I won’t be using an API so Fortify should be enough for authentication.

Am I missing something?

0 likes
2 replies
LaryAI's avatar
Level 58

It sounds like there might be a misconfiguration in your Laravel project. Laravel Jetstream uses Laravel Sanctum for API token authentication by default, even if you're not planning to use the API features. Therefore, Sanctum should be installed and configured as part of the Jetstream installation process.

Here's what you can do to resolve the issue:

  1. Ensure Sanctum is installed by running the following command:
composer require laravel/sanctum
  1. After installing Sanctum, you need to publish its configuration file:
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
  1. Run the migrations to create the necessary tables for Sanctum:
php artisan migrate
  1. Ensure that your config/auth.php configuration file has the sanctum guard set up correctly. It should look something like this:
'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'sanctum',
        'provider' => 'users',
        'hash' => false,
    ],
],
  1. In your App\Models\User model, make sure to use the Laravel\Sanctum\HasApiTokens trait:
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
    // ...
}
  1. Finally, clear your configuration cache to ensure all changes take effect:
php artisan config:cache

After following these steps, try registering a new user again. The Sanctum-related error should be resolved.

Regarding your question about whether the install should include Sanctum if it is required: yes, it should. If it didn't, it might have been a temporary issue with the installer or a misstep during the installation process. By following the steps above, you should be able to manually add and configure Sanctum in your project.

If you're certain you won't be using any API features and want to remove Sanctum, you can do so, but you'll need to ensure that your application is configured correctly to handle authentication without it. However, since Jetstream is tightly integrated with Sanctum, it's generally easier to leave it installed.

rubendn's avatar

Forgot to mention that this is on Windows.

Found it strange that it is relying on Sanctum but it was not installed during the installation process.

I tried the installation multiple times with the same result using both "laravel new" and "composer create-project". Sanctum did not install on any of the attempts and the same errors until I added Sanctum.

Please or to participate in this conversation.