Kawaii-jwt (JWT) for Laravel 5.5+ and Quasar BoilerPlate
, (*1)
- Kawaii-jwt is API from Quasar BoilerPlate - BoilerPlate
ReLations packets:, (*2)
Installation
- composer create-project kawaiiwaifus/laravel-api-kawaii-jwt NameOfProject
Usage
- run the
php artisan migrate
- run the
php artisan db:seed
for create tests users.
Main Features
A Ready-To-Use Authentication Controllers
You don't have to worry about authentication and password recovery anymore.
I created four controllers you can find in the App\Api\V1\Controllers
for those operations., (*3)
For each controller there's an already setup route in routes/api.php
file:, (*4)
-
POST api/auth/login
, to do the login and get your access token;
-
POST api/auth/refresh
, to refresh an existent access token by getting a new one;
-
POST api/auth/register
, to create a new user into your application;
-
POST api/auth/recovery
, to recover your credentials;
-
POST api/auth/reset
, to reset your password after the recovery;
-
POST api/auth/logout
, to log out the user by invalidating the passed token;
-
GET api/auth/me
, to get current user data;
A Separate File for Routes
All the API routes can be found in the routes/api.php
file. This also follow the Laravel 5.5., (*5)
Secrets Generation
Every time you create a new project starting from this repository, the php artisan jwt:generate command will be executed., (*6)
Configuration
Database example:, (*7)
DROP TABLE IF EXISTS `users`;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(120) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(120) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(125) COLLATE utf8_unicode_ci NOT NULL,
`remember_token` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`telephone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
`active` int(1) NOT NULL DEFAULT '0',
`gender` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,
`address` varchar(190) COLLATE utf8_unicode_ci DEFAULT NULL,
`amount` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `users_email_unique` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=325 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
You can find all the Kawaii-jwt specific settings in the config/kawaii-jwt.php
config file., (*8)
<?php
return [
// these options are related to the sign-up procedure
'sign_up' => [
// this option must be set to true if you want to release a token
// when your user successfully terminates the sign-in procedure
'release_token' => env('SIGN_UP_RELEASE_TOKEN', false),
// here you can specify some validation rules for your sign-in request
'validation_rules' => [
'name' => 'required',
'email' => 'required|email',
'password' => 'required'
]
],
// these options are related to the login procedure
'login' => [
// here you can specify some validation rules for your login request
'validation_rules' => [
'email' => 'required|email',
'password' => 'required'
]
],
// these options are related to the password recovery procedure
'forgot_password' => [
// here you can specify some validation rules for your password recovery procedure
'validation_rules' => [
'email' => 'required|email'
]
],
// these options are related to the password recovery procedure
'reset_password' => [
// this option must be set to true if you want to release a token
// when your user successfully terminates the password reset procedure
'release_token' => env('PASSWORD_RESET_RELEASE_TOKEN', false),
// here you can specify some validation rules for your password recovery procedure
'validation_rules' => [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed'
]
]
];
As I already said before, this Kawaii-jwt is based on dingo/api and tymondesigns/jwt-auth packages. So, you can find many informations about configuration here and here., (*9)
However, there are some extra options that I placed in a config/kawaii-jwt.php file:, (*10)
-
sign_up.release_token
: set it to true
if you want your app release the token right after the sign up process;
-
reset_password.release_token
: set it to true
if you want your app release the token right after the password reset process;
There are also the validation rules for every action (login, sign up, recovery and reset). Feel free to customize it for your needs., (*11)
Creating Endpoints
You can create endpoints in the same way you could to with using the single dingo/api package. You can read its documentation for details. After all, that's just a boilerplate! :), (*12)
However, I added some example routes to the routes/api.php
file to give you immediately an idea., (*13)
Cross Origin Resource Sharing
If you want to enable CORS for a specific route or routes group, you just have to use the cors middleware on them., (*14)
Thanks to the barryvdh/laravel-cors package, you can handle CORS easily. Just check the docs at this page for more info., (*15)
Tests
CREDITS: