Add initial authentication system

This commit is contained in:
KevinNThomas
2021-07-17 15:39:23 -07:00
parent b742befdbd
commit 1871ea9eb7
34 changed files with 18053 additions and 1 deletions

64
src/components/Login.vue Normal file
View File

@@ -0,0 +1,64 @@
<template>
<div>
<h4>Login</h4>
<form>
<label for="email">E-Mail Address</label>
<div>
<input id="email" type="email" v-model="email" required autofocus />
</div>
<div>
<label for="password">Password</label>
<div>
<input id="password" type="password" v-model="password" required />
</div>
</div>
<div>
<button type="submit" @click="handleSubmit">Login</button>
</div>
</form>
</div>
</template>
<script>
export default {
data() {
return {
email: "",
password: "",
};
},
methods: {
handleSubmit(e) {
e.preventDefault();
if (this.password.length > 0) {
this.$http
.post("http://localhost:3000/login", {
email: this.email,
password: this.password,
})
.then((response) => {
let is_admin = response.data.user.is_admin;
localStorage.setItem("user", JSON.stringify(response.data.user));
localStorage.setItem("jwt", response.data.token);
if (localStorage.getItem("jwt") != null) {
this.$emit("loggedIn");
if (this.$route.params.nextUrl != null) {
this.$router.push(this.$route.params.nextUrl);
} else {
if (is_admin == 1) {
this.$router.push("admin");
} else {
this.$router.push("dashboard");
}
}
}
})
.catch(function (error) {
console.error(error.response);
});
}
},
},
};
</script>