bitfumes / api-auth
Your Package Description here
v6.0.0
2023-03-21 05:40 UTC
Requires
- intervention/image: ^2.7
- laravel/sanctum: ^3
- laravel/socialite: ^5.6
- laravel/ui: ^4.2
- tymon/jwt-auth: ^2.0
Requires (Dev)
- fakerphp/faker: ^1.9.1
- illuminate/support: ^10
- laravel/legacy-factories: ^1.0@dev
- mockery/mockery: ^1.4
- orchestra/testbench: ^8
- phpunit/phpunit: ^10
README
Install
composer require bitfumes/api-auth
Steps to follow
Steps 1
- Add Contract
hasApiAuth
andJWTSubject
to your authenticatable model like shown below: - Add
ApiAuth
trait to your user model.
use Bitfumes\ApiAuth\Traits\ApiAuth; use Tymon\JWTAuth\Contracts\JWTSubject; use Bitfumes\ApiAuth\Contract\HasApiAuth; class User extends Authenticatable implements HasApiAuth, JWTSubject { use Notifiable, ApiAuth; ... }
Step 2
Configure your config/auth.php file to update guard details
- Update default guard to api
'defaults' => [ 'guard' => 'api', ... ],
- Update api guard to 'jwt'
'guards' => [ ... , 'api' => [ 'driver' => 'jwt', ... ], ],
Step 3
Add new accessor to your authenticatable model
public function setPasswordAttribute($value) { $this->attributes['password'] = bcrypt($value); }
Step 4
Now publish two new migrations
- To add avatar field to your use model.
- To add social login profile.
php artisan vendor:publish --tag=api-auth:migrations
Step 5
After getting migrations in your laravel application, its time to have these tables in your database.
php artisan migrate
Step 6
Because every user need to verify its email and to send email we are going to use laravel queue.
Now add queue driver on your .env
file
That's it, now enjoy api auth with JWT
QUEUE_DRIVER=database
Testing
Run the tests with:
vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email sarthak@bitfumes.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.