Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<template>
<div>
<div class="flex items-center justify-center">
<div class="sm:block">
<div class="p-5 mx-auto text-left font-raleway">
<h1 class="font-bold text-left font-montserrat text-3xl sm:text-5xl mb-7">
Login to DD-Code
</h1>
<p v-show="error" class="text-lg text-red-500">{{ errorMsg }}</p>
<form @submit="login">
<div class="my-4">
<h1 class="text-left font-bold mb-2 text-xl sm:text-2xl font-montserrat">Email</h1>
<input type="email" v-model="email" class="text-xl outline-none pt-3 pb-3 w-4/5 bg-transparent border-b hover:border-blue-700 focus:border-blue-700">
</div>
<div class="my-4">
<h1 class="text-left font-bold mb-2 text-xl sm:text-2xl font-montserrat">Password</h1>
<input type="password" v-model="password" class="text-xl outline-none pt-3 pb-3 w-4/5 bg-transparent border-b hover:border-blue-700 focus:border-blue-700">
</div>
<button type="submit" :disabled="password.length < 3" class="bg-green-400 p-5 text-white">
Login <span class="fa fa-arrow-right"/>
</button>
<p class="my-2">
<router-link to="/forgotpassword" >Forgot Password?</router-link>
</p>
<p class="my-2">
<router-link to="/signup" >Need Sign Up?</router-link>
</p>
</form>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'Login',
data() {
return {
email: '',
password: '',
error: false,
errorMsg: `An error occurred, please try again`
}
},
computed: {
userData: function () {
return this.$store.getters['User/userData']
},
},
methods: {
async login(e) {
e.preventDefault()
try {
const res = await this.axios.post(`http://localhost:1337/api/auth/local`, {
identifier: this.email,
password: this.password
});
const { jwt, user } = res.data
console.log(user)
window.localStorage.setItem('jwt', jwt)
window.localStorage.setItem('userData', JSON.stringify(user))
this.$store.dispatch('User/setJwt', jwt)
this.$store.dispatch('User/setUserData', user)
this.$router.push('/profile')
} catch(error) {
// console.log(error.response.data.error.message)
this.error = true
this.password = ''
}
},
},
mounted: function () {
const vm = this
if(vm.userData !== null) {
this.$router.push('/profile')
}
}
}
</script>
<style>
@import url('~@/assets/bootstrap.css');
a {
color: #42b983;
}
</style>