cetria/laravel-auth

Laravel package providing customizable authentication API endpoints using Sanctum and Bearer tokens.

Maintainers

Package info

bitbucket.org/gigaprint/cetria-laravel-auth

pkg:composer/cetria/laravel-auth

Transparency log

Statistics

Installs: 215

Dependents: 0

Suggesters: 0

2.2 2026-06-30 09:46 UTC

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

  1. 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,
    
  2. Add the custom guard to config/auth.php:
    'guards' => [
     'sanctumWithSpecialTokenNames' => [
         'driver' => 'sanctumWithSpecialTokenNames',
         'provider' => 'users',
     ],
    ],
    
  3. Add the Laravel\Sanctum\HasApiTokens trait 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