colbeh/auth
Laravel authentication package by colbeh. Provides auth-related helpers and integrations to simplify login/guard setup and user access in your app. Suitable as a lightweight add-on for projects needing basic authentication scaffolding.
Installation
composer require colbeh/auth
Publish the package configuration and migrations:
php artisan vendor:publish --provider="Colbeh\Auth\AuthServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="Colbeh\Auth\AuthServiceProvider" --tag="config"
Run migrations:
php artisan migrate
Configuration
Update .env with your desired auth driver (e.g., database, ldap, or oauth).
Modify config/auth.php to align with the package’s expected structure (e.g., providers and guards).
First Use Case: Basic Login Use the provided facade or service to authenticate:
use Colbeh\Auth\Facades\Auth;
$credentials = ['email' => '[email protected]', 'password' => 'password'];
if (Auth::attempt($credentials)) {
$user = Auth::user();
// Redirect or proceed...
}
Routes
Register auth routes in routes/web.php:
Route::auth(); // Uses package's default routes (login, register, logout)
Authentication
Auth::login($user); // Manually log in a user
Auth::logout(); // Log out current user
Auth::attempt($credentials); // Attempt login
auth or guest middleware (package-compatible) in routes/controllers:
Route::middleware(['auth'])->group(function () {
// Protected routes
});
Registration
RegisterController (if provided) or use the facade:
$user = Auth::register([
'name' => 'John Doe',
'email' => '[email protected]',
'password' => bcrypt('password'),
]);
Password Reset
Password facade or leverage built-in routes:
use Colbeh\Auth\Facades\Password;
$response = Password::sendResetLink(['email' => '[email protected]']);
Custom Guards
config/auth.php:
'guards' => [
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
Auth::guard('api')->attempt($credentials);
Session Handling
Auth::regenerateSessionId();
if (Auth::check()) {
// User is authenticated
}
Laravel Ecosystem
Auth::user() returns a User model).Colbeh\Auth\Models\User or binding your own model.API Authentication
Sanctum or Passport alongside this package. Configure the api guard to use token driver.Social Logins (OAuth)
config/services.php and use:
Auth::loginUsingId($providerUserId);
Event Listeners
auth.login, auth.logout) via Event::listen or service providers.Testing
Auth::actingAs($user) in tests to simulate authentication:
$this->actingAs($user)->get('/profile');
Migration Conflicts
users table. Solution:
config/auth.php or drop existing migrations before running php artisan migrate.Deprecated Methods
Auth::once()). Solution:
README or source code for deprecated features. Update to modern Laravel auth patterns if needed.No Built-in Views
resources/views/auth.LDAP/OAuth Limitations
config/auth.php and install required PHP extensions (e.g., php-ldap).Session Driver Issues
database or redis session driver, ensure the session table is properly configured. Solution:
php artisan session:table and migrate if needed.Authentication Failures
config/auth.php for correct provider and guard settings.dd(Hash::check('plain-text', $user->password)); // Debug password hashing
Route Conflicts
/login conflict with existing routes, override them in routes/web.php:
Route::get('/custom-login', [AuthController::class, 'showLoginForm'])->name('login');
Logging
APP_DEBUG=true in .env) and check logs in storage/logs/laravel.log for auth errors.Custom User Model
AuthServiceProvider:
public function boot()
{
$this->app['auth']->extend('custom', function ($app) {
return new CustomAuthGuard($app['auth']->createUserProvider('eloquent'));
});
}
Custom Auth Logic
AuthManager or Guard implementations by publishing and modifying the package’s source files (located in vendor/colbeh/auth).Adding Fields to Registration
User model:
// In User model
protected $fillable = ['name', 'email', 'password', 'phone'];
// In RegisterController (if provided)
public function validator(array $data)
{
return Validator::make($data, [
'phone' => 'required|unique:users',
// ...
]);
}
Two-Factor Authentication (2FA)
two-factor package or implement custom logic using the package’s auth events.Rate Limiting
throttle middleware:
Route::post('/login', [AuthController::class, 'login'])->middleware('throttle:5,1');
How can I help you explore Laravel packages today?