- Laravel 5.7
- tymon/jwt-auth:dev-develop
- Vuejs
- Vue Router
- Vue axios
- @websanova/vue-auth
npm install
npm install --save-dev vue-axios vue-router vue-loader vue-template-compiler
App.vue
is the main front end file, with the header links (<router-link>
) and, renders the vue components. (<router-view>
)
Home.vue
is the component loaded when you are not logged in.
app.js
is where setup vue, vue-router and load all the vue single file components.
welcome.blade.php
is the file loaded when first visit the site. Since the site is single page, on laravel side is the unique web route to be loaded.
npm run watch
watches for changes in the js/vue files and recompile.
In the js/components
create the files Login.vue
, Register.vue
, UserDetail.vue
, Users.vue
.
These files are like the .blade.php in laravel.
Import and setup the routes for the vue components in the resources/js/app.js
To handle the authentication on the frontend side, npm install @websanova/vue-auth
and update resources/js/app.js
meta{auth : true / false}
are the routes / requests authentications.
On resources/js/app.js
:
auth: require(‘@websanova/vue-auth/drivers/auth/bearer.js’)
configures the vue-router to use the bearer driver to handle the authentication token.
http: require(‘@websanova/vue-auth/drivers/http/axios.1.x.js’)
configures the vue-auth to use axios http driver for http requests.
router: require(‘@websanova/vue-auth/drivers/router/vue-router.2.x.js’)
configures the vue-auth to use vue-router
composer require tymon/jwt-auth:dev-develop
Generate JWT keys:
php artisan jwt:secret
Change config/auth.php
defaults->guard to api
, and guards
-> api
-> driver
to jwt
.
Modify app/User.php
User model to implement JWT tokens.
On app/Http/Kernel.php
on application's route middleware add jwt.auth
and jwt.refresh
:
protected $routeMiddleware = [
...
'jwt.auth' => \Tymon\JWTAuth\Middleware\GetUserFromToken::class,
'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class,
];
make the controller with
php artisan make:controller AuthController
fill the controller, and add the routes on routes/api.php