Created
October 4, 2020 03:14
-
-
Save blogcacanid/ad747dd852acabca13e9e0ca1cbdf4a5 to your computer and use it in GitHub Desktop.
LoginComponent.vue - Login System Dengan JSON Web Token Laravel 7 Dan Vue - 02 Front End
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="text-center form-wrapper"> | |
<form class="form-signin" v-on:submit.prevent="submitLogin"> | |
<img class="mb-4" src="https://cacan.id/wp-content/uploads/my_blog/cacan-400x400.jpg" alt="" width="72" height="72"> | |
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1> | |
<label for="inputEmail" class="sr-only">Email address</label> | |
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus v-model="email"> | |
<label for="inputPassword" class="sr-only">Password</label> | |
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required v-model="password"> | |
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button> | |
</form> | |
</div> | |
</template> | |
<script> | |
import store from '../store' | |
export default { | |
data() { | |
return { | |
email: '', | |
password: '', | |
loginError: false, | |
} | |
}, | |
methods: { | |
submitLogin() { | |
this.loginError = false; | |
axios.post('/api/auth/login', { | |
email: this.email, | |
password: this.password | |
}).then(response => { | |
// login user, store the token and redirect to dashboard | |
store.commit('loginUser') | |
localStorage.setItem('token', response.data.access_token) | |
this.$router.push({ name: 'home' }) | |
}).catch(error => { | |
this.loginError = true | |
}); | |
} | |
} | |
} | |
</script> | |
<style scoped> | |
.form-wrapper { | |
min-height: 100%; | |
min-height: 100vh; | |
display: flex; | |
align-items: center; | |
} | |
.form-signin { | |
width: 100%; | |
max-width: 330px; | |
padding: 15px; | |
margin: 0 auto; | |
} | |
.form-signin .form-control { | |
position: relative; | |
box-sizing: border-box; | |
height: auto; | |
padding: 10px; | |
font-size: 16px; | |
} | |
.form-signin .form-control:focus { | |
z-index: 2; | |
} | |
.form-signin input[type="email"] { | |
margin-bottom: -1px; | |
border-bottom-right-radius: 0; | |
border-bottom-left-radius: 0; | |
} | |
.form-signin input[type="password"] { | |
margin-bottom: 10px; | |
border-top-left-radius: 0; | |
border-top-right-radius: 0; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment