- Can BetterAuth Multimodal PHP replace Laravel’s built-in authentication (e.g., Laravel Breeze/Sanctum) entirely?
- Yes, but with trade-offs. The package supports session-based auth (like Laravel’s default) and token-based (Paseto V4) for APIs, replacing Sanctum/JWT. However, you’ll need to adapt Laravel’s middleware (e.g., `auth:api`) and handle storage via PDO or custom Eloquent adapters, which may require additional setup.
- How does Paseto V4 token authentication compare to Laravel Sanctum or JWT for Laravel APIs?
- Paseto V4 is more secure than JWT (no secret management, public-key cryptography) but requires the `sodium` extension and may introduce larger payloads. Sanctum/JWT are more Laravel-optimized with built-in middleware, caching, and queue support. Paseto is ideal if you prioritize security over simplicity or existing JWT expertise.
- Does BetterAuth support Laravel’s Eloquent ORM, or is PDO storage mandatory?
- PDO storage is provided out-of-the-box, but Eloquent support isn’t native. You’d need to create custom repositories or adapters to bridge the gap, which could introduce complexity. For teams deeply invested in Eloquent, this might not be the lowest-friction option.
- How do I integrate OAuth social logins (e.g., Google, GitHub) in Laravel with this package?
- BetterAuth includes built-in OAuth support for providers like Google and GitHub. Configure the `AuthConfig` with your OAuth credentials, then use the `auth->signInWithOAuth()` method. For Laravel’s routing, you’ll need to handle the OAuth redirect flow via middleware (e.g., `web` middleware for session-based logins).
- Is multi-tenancy support in BetterAuth compatible with Laravel’s global/scoped models or packages like spatie/laravel-multitenancy?
- BetterAuth has native multi-tenancy features (organizations, teams, members), but it’s not designed specifically for Laravel’s scoped models. You’d need to align its storage layer (PDO) with your tenancy strategy. For deeper Laravel integration, spatie/laravel-multitenancy might offer tighter compatibility.
- What Laravel versions are supported, and are there any PHP version conflicts?
- BetterAuth requires PHP 8.2+, which aligns with Laravel 10+. There are no version conflicts, but ensure your Laravel app meets the PHP 8.2+ requirement. The package is framework-agnostic, so it won’t interfere with Laravel’s core auth system unless you actively replace it.
- How do I handle token validation in API routes (e.g., replacing Laravel Sanctum’s `auth:sanctum`)?
- Use the `AuthManager` to validate Paseto tokens in middleware. For example, create a custom middleware extending Laravel’s `Middleware` class to call `$auth->validateToken($token)`. This replaces Sanctum’s `auth:sanctum`, but you’ll need to manually handle token extraction from headers/cookies.
- Are there performance considerations for Paseto tokens in high-traffic Laravel APIs?
- Paseto tokens are larger than JWTs due to public-key cryptography, which may impact payload sizes or storage. For high-throughput APIs, test token generation/validation latency. The `sodium` extension is critical for performance—ensure it’s enabled. Caching token validation (e.g., Redis) could mitigate overhead.
- Can I use BetterAuth’s plugin system to extend functionality (e.g., custom user events) in Laravel?
- Yes, the plugin system includes hooks like `user.created` or `token.created` that you can bind to Laravel’s event system. For example, trigger a Laravel event in a plugin’s `onUserCreated` method. This allows seamless integration with Laravel’s service providers and listeners.
- What are the alternatives to BetterAuth for Laravel, and when should I choose this package?
- Alternatives include Laravel Sanctum (API tokens), Laravel Breeze (session auth), or packages like `league/oauth2-server` for OAuth. Choose BetterAuth if you need a unified session/token/OAuth solution with Paseto V4, multi-tenancy, or advanced security features like adaptive risk scoring. It’s ideal for apps requiring both web and API auth with minimal third-party dependencies.