composer require bitfumes/api-auth
- 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;
...
}
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',
...
],
],
Add new accessor to your authenticatable model
public function setPasswordAttribute($value)
{
$this->attributes['password'] = bcrypt($value);
}
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
After getting migrations in your laravel application, its time to have these tables in your database.
php artisan migrate
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
Run the tests with:
vendor/bin/phpunit
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email sarthak@bitfumes.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.