Registration Log in using Laravel + VueJS

Tram Ho

1. Introduction

Hello everyone, I have time to come back to continue with Vuejs Spa + Laravel authentiaction jwt series. Let’s start too.

2. Back end (Laravel)

Step 1

  • Create a Laravel composer create-project --prefer-dist laravel/laravel learning project composer create-project --prefer-dist laravel/laravel learning

run comand line :

  • composer install
  • php artisan key: generate
  • cp .env.example .env
  • composer require laravel / ui (package laravel ui)
  • After running php Artisan after running, you can see a component folder in resoures / js
  • npm install or yarn install to describe packages.

Install the JWT package

  • composer requires tymon / jwt-auth
  • Next open config / app.php: add provider: Tymon JWTAuth Providers LaravelServiceProvider :: class, add aliases

then we publish it: php artisan vendor:publish --provider="TymonJWTAuthProvidersLaravelServiceProvider"

Step 2

First create 1 controller:

php artisan make:controller api/SinglePageController The purpose of this Controller is to return the view using vueJs.

Step 3

A token generated when we login will return the User model. The User model will implement JWTSubject and update the model again:

Step 4 Update Authentication Middleware

Update them to middeware Autenticate.php

Step 5

Next we create a controller to serve the view, create, update php artisan make:controller api/UserController

Step 6 – Blade

Throw this in resources / views / welcome.blade.php

3 Client (VueJs)

Step 1

Clien, we use 2 packages, vue-router and websanova / vue-auth

Webpack Mix Mix js file and style into public folder, I also want to use the path to access Vue components more easily so I will use alias

Now access the vue components in resoure / js directory, just replace with @ /

Step 2 – Router

Step 3 – Config vue-auth

Create a user.js file in resources

Step 4 – App

app.js here it will be a file used for all components

Step 5

Create 1 AppComponent.vue

Step 6

Need to add a TopBar component to see who is currently logged in and performing the logout. This component is only available when the system has been authenticated using the v-if = “$ auth.check ()” function.

Step 7

Create a new 1 RegisterComponent.vue

Step 8

Next is LoginComponent.vue

Step 9

Finally, HomeComponent. When the login is complete, the website will redirect to this page

4 Finish

Hope the article will bring a lot of things to you. To add motivation or like and subscribe (Upvote for me). Any questions please comment or below. Thank you for read.

Share the news now

Source : Viblo