cetria / laravel-auth
Laravel package providing customizable authentication API endpoints using Sanctum and Bearer tokens.
2.2
2026-06-30 09:46 UTC
Requires
- php: ^8.4
- laravel/framework: ^12.0
- laravel/sanctum: ^4.0
Requires (Dev)
- cetria/reflection-helper: ^0.4.2
- orchestra/testbench: ^10.0
- slevomat/coding-standard: ^8.18
- squizlabs/php_codesniffer: *
This package is auto-updated.
Last update: 2026-06-30 09:50:50 UTC
README
Custom Laravel package providing ready-to-use authentication API endpoints using Sanctum and Bearer tokens.
Features
- Plug-and-play authentication routes
- Login with token creation (
/auth) - Get current user (
/me) - Logout current device (
/logout) - Logout all devices (
/allDeviceLogout) - Custom guard with named tokens (e.g.
devel,mobile, etc.)
Installation
composer require cetria/cetria-laravel-auth
Configuration
- Register the service provider (if not auto-discovered).
If your Laravel version does not support package auto-discovery or you have it disabled, manually register the service provider in
bootstrap/providers.php:Cetria\Laravel\Auth\Providers\SanctumWithSpecialTokenNames::class, - Add the custom guard to
config/auth.php:'guards' => [ 'sanctumWithSpecialTokenNames' => [ 'driver' => 'sanctumWithSpecialTokenNames', 'provider' => 'users', ], ], - Add the
Laravel\Sanctum\HasApiTokenstrait to your authentication model:use Illuminate\Foundation\Auth\User as Authenticatable; use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable {
use HasApiTokens;
// ...
}
## Usage
Define routes in `routes\api.php`:
use Illuminate\Support\Facades\Route; use Cetria\Laravel\Auth\Providers\SanctumWithSpecialTokenNames;
Route::post('/auth', [Auth::class, 'auth'])->name('auth');
// Protected routes Route::middleware('auth:' . SanctumWithSpecialTokenNames::$guardName)->group(function () {
Route::get('/me', [Auth::class, 'me'])->name('me');
Route::get('/logout', [Auth::class, 'logout'])->name('logout');
Route::get('/allDeviceLogout', [Auth::class, 'logoutAllDevices'])->name('logoutAllDevices');
// Add more authenticated routes here...
});
## Testing
This package includes pre-built **feature tests** for the authentication endpoints and the custom guard.
### Requirements
To run the tests, make sure the following dependencies are installed:
- `phpunit >= 11.0`
- `cetria/reflection >= 0.2`
#### Auth User Model
Your user model must:
- implements `Cetria\Laravel\Auth\Interfaces\AuthUser`
- Use the `Illuminate\Database\Eloquent\Factories\HasFactory` trait
#### Auth User Factory
Your factory class must:
- implements the `Cetria\Laravel\Auth\Interfaces\AuthModelFactory`
- Use the `Cetria\Laravel\Auth\Traits\AuthModelFactory` trait
### Setup
Once the requirements are met, add the test directory to your `phpunit.xml` configuration:
vendor/cetria/laravel-auth/src/Tests/Feature