mediadotonedev / userauthcenter
A Laravel package for user authentication with OTP and password
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:laravel-package
pkg:composer/mediadotonedev/userauthcenter
Requires
- php: ^8.0
- illuminate/auth: ^10.0|^11.0|^12.0
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/http: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- laravel/sanctum: ^3.0|^4.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.0
This package is auto-updated.
Last update: 2025-11-21 19:44:36 UTC
README
UserAuthCenter is a comprehensive Laravel package designed to provide robust user authentication functionalities, including OTP (One-Time Password) and traditional password-based authentication. This package aims to simplify the integration of advanced authentication features into your Laravel applications.
Table of Contents
Installation
To install UserAuthCenter, require it via Composer in your Laravel project:
composer require mediadotonedev/userauthcenter:dev-main php artisan vendor:publish --tag=userauthcenter-config php artisan vendor:publish --tag=userauthcenter-controllers php artisan vendor:publish --tag=userauthcenter-requests php artisan vendor:publish --tag=userauthcenter-rules php artisan vendor:publish --tag=userauthcenter-migrations php artisan migrate php artisan vendor:publish --tag=userauthcenter-models --force php artisan vendor:publish --tag=userauthcenter-services php artisan l5-swagger:generate
After installing the package, Laravel will automatically discover the package's service provider. No manual registration is required for Laravel versions 5.5 and above.
Configuration
The package comes with a configurable file userauthcenter.php. You can publish this configuration file to your application's config directory to customize its settings.
To publish the configuration file, run:
php artisan vendor:publish --tag=userauthcenter-config
This will copy vendor/mediadotonedev/userauthcenter/src/config/userauthcenter.php to config/userauthcenter.php.
Database Migrations
This package includes its own database migrations for user-related tables or modifications. It's crucial to run these migrations to set up your database correctly.
First, you can publish the migrations to your application's database/migrations directory:
php artisan vendor:publish --tag=userauthcenter-migrations
After publishing, run your database migrations:
php artisan migrate
Note: If you already have a users table, the package's migration (update_users_table.php) might attempt to modify it. Review the migration file to ensure it aligns with your existing database schema.
Publishing Files
UserAuthCenter allows you to publish several of its internal files to your application. This is useful if you need to modify or extend the package's core logic or components directly.
Configuration File
As mentioned above, to publish the configuration file:
php artisan vendor:publish --tag=userauthcenter-config
Controllers
To publish the UserAuthController.php to app/Http/Controllers/:
php artisan vendor:publish --tag=userauthcenter-controllers
Requests
To publish all validation request files to app/Http/Requests/:
php artisan vendor:publish --tag=userauthcenter-requests
Rules
To publish custom validation rules (e.g., EmailOrIranianMobile.php) to app/Rules/:
php artisan vendor:publish --tag=userauthcenter-rules
Models
To publish the User.php model to app/Models/:
php artisan vendor:publish --tag=userauthcenter-models --force
Important: Publishing the User.php model might conflict with your existing App\Models\User.php. Exercise caution and merge changes manually if necessary, or consider using a different model name within your package if a direct conflict is undesirable.
Services
To publish service classes (e.g., UserAuthService.php, UserService.php) to app/Services/:
php artisan vendor:publish --tag=userauthcenter-services
Swagger Configuration
If your package includes Swagger/OpenAPI documentation, you can publish its configuration:
php artisan l5-swagger:generate
All Publishable Files
To publish all the above-mentioned files (config, migrations, controllers, requests, rules, models, services, swagger config) with a single command:
php artisan vendor:publish --provider="Mediadotonedev\UserAuthCenter\UserauthcenterServiceProvider"
Or, if you define an userauthcenter-all tag in your ServiceProvider:
php artisan vendor:publish --tag=userauthcenter-all
API Config
add environment packacage connect to api append .env file.
USERAUTHCENTER_API_KEY= USERAUTHCENTER_API_URL=
Usage
API Routes
The package provides its own API routes for authentication. These routes are automatically loaded by the package and do not overwrite your application's routes/api.php.
The API routes are defined in vendor/mediadotonedev/userauthcenter/src/routes/userauthcenter_api.php. You can inspect this file to see the available endpoints.
Typically, these routes would handle:
- User registration (with or without OTP)
- User login (password-based or OTP-based)
- OTP generation and verification
- Password reset functionalities
Example: If your package defines /api/auth/register, you can access it directly after installation.
Extending Functionality
Since you can publish various components like controllers, requests, rules, and models, you have the flexibility to extend or override the package's default behavior by modifying the published files.
update package
composer dump-autoload php artisan config:clear
Contribution
Feel free to contribute to the UserAuthCenter package. Bug reports, feature requests, and pull requests are welcome.
License
The UserAuthCenter package is open-sourced software licensed under the MIT license.