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:
- Ensure Sanctum is installed by running the following command:
composer require laravel/sanctum
- After installing Sanctum, you need to publish its configuration file:
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
- Run the migrations to create the necessary tables for Sanctum:
php artisan migrate
- Ensure that your
config/auth.phpconfiguration file has thesanctumguard set up correctly. It should look something like this:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'sanctum',
'provider' => 'users',
'hash' => false,
],
],
- In your
App\Models\Usermodel, make sure to use theLaravel\Sanctum\HasApiTokenstrait:
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
// ...
}
- 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.