joe-404/laravel-auth
Config-driven, drop-in auth for Laravel 12/13: JSON API for registration with OTP/magic-link verification, login, refresh tokens, password reset, Google OAuth, multi-session/device fingerprinting, long-lived API tokens, account status workflows, and referrals.
Installation:
composer require joe-404/laravel-auth
php artisan auth:install
User Model:
Add traits to app/Models/User.php:
use HasApiTokens, HasRoles, Notifiable, SoftDeletes, HasAccountStatus;
Environment:
Set .env variables (minimal):
AUTH_MODE=both
AUTH_VERIFICATION_METHOD=both
MAIL_MAILER=smtp
MAIL_FROM_ADDRESS=hello@yourapp.com
First Use Case: Test registration flow:
curl -X POST http://localhost/auth/register -H "Content-Type: application/json" -d '{"email":"test@example.com"}'
Follow with OTP verification and completion.
Registration Flow:
temp_token (OTP + magic link).completion_token.Login/Logout:
/auth/login (password) or /auth/social/google/redirect (OAuth)./auth/logout (current session) or /auth/logout/all (all sessions).Password Management:
/auth/password/forgot → OTP → /auth/password/reset/confirm./auth/password/change.API Tokens:
/auth/api-tokens (user-scoped) or /auth/admin/api-tokens (admin).Account Status:
/auth/admin/users/{id}/status./auth/account/deactivate.config/auth_system.php (e.g., disable OTP, enforce 2FA).AccountRegistered, PasswordReset).deleted_accounts table.Override default fields in config/auth_system.php:
'registration' => [
'fields' => [
'email' => true,
'name' => true,
'phone' => false, // Disable phone field
'terms_accepted' => true,
],
],
OTP/Magic Link Expiry:
AUTH_VERIFICATION_EXPIRY_MINUTES)./auth/email/resend-verification.Session Management:
php artisan sanctum:prune periodically.Account Deletion:
hard_delete_after_grace=true, the users row is permanently deleted after grace. Ensure deleted_accounts table retains audit data.Google OAuth:
config/services/google.callback (default: http://localhost/auth/social/google/callback).AUTH_SOCIAL_GOOGLE_ENABLED=true in .env.Unique Columns:
null_uniques_after_grace=true, unique fields (e.g., email) are nulled post-grace. Ensure your app handles this (e.g., no duplicate emails).AUTH_DEBUG=true in .env for verbose logging.AccountDeleted or AccountRestored for custom logic:
Event::listen(AccountDeleted::class, function ($event) {
// Custom logic (e.g., notify admins)
});
php artisan queue:work to process deferred tasks (e.g., purge worker).Custom Verification:
Override Joe404\LaravelAuth\Contracts\VerificationService to add SMS/phone verification.
Email Templates: Publish and override templates:
php artisan vendor:publish --tag=laravel-auth-views
Edit resources/views/vendor/laravel-auth/emails/otp.blade.php.
Account Status Middleware:
Use auth.active middleware to restrict access:
Route::middleware(['auth:sanctum', 'auth.active'])->group(function () {
// Protected routes
});
Referral Codes: Enable via config:
'referrals' => [
'enabled' => true,
'field' => 'referral_code',
],
Add to registration fields and track via ReferralCreated event.
AUTH_MODE:
web: Session-based auth (cookies).api: Token-based (Sanctum).both: Hybrid (default).AUTH_VERIFICATION_METHOD:
otp: One-time password.magic: Magic links.both: Both (default).predis or phpredis.AUTH_RATE_LIMIT.How can I help you explore Laravel packages today?