2024-06-10 15:10:22 +00:00
|
|
|
<script setup>
|
2024-06-11 18:15:29 +00:00
|
|
|
import CreateSecret from "./components/CreateSecret.vue";
|
2024-06-13 17:54:48 +00:00
|
|
|
import HomePage from "./components/HomePage.vue";
|
2024-06-13 05:11:56 +00:00
|
|
|
import ListSecrets from "./components/ListSecrets.vue";
|
2024-06-10 15:10:22 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
2024-06-15 15:44:49 +00:00
|
|
|
<div id="header">
|
|
|
|
<span class="logo">FastAuth</span>
|
|
|
|
<div class="header-buttons" v-if="loggedin">
|
|
|
|
<el-button type="primary" class="ml-2" @click="creationDialog = true">
|
|
|
|
Create
|
|
|
|
</el-button>
|
|
|
|
<el-button type="warning" class="ml-2" @click="logout">Logout</el-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-13 05:11:56 +00:00
|
|
|
|
|
|
|
<el-dialog v-model="creationDialog" title="Add a new TOTP secret" width="80vw">
|
2024-06-13 17:02:47 +00:00
|
|
|
<CreateSecret @close="creationDialog = false" />
|
2024-06-13 05:11:56 +00:00
|
|
|
</el-dialog>
|
|
|
|
|
|
|
|
<div class="container">
|
2024-06-14 18:42:02 +00:00
|
|
|
<HomePage
|
|
|
|
msg="You did it!"
|
|
|
|
@loggedin="
|
|
|
|
loggedin = true;
|
|
|
|
showSecrets = true;
|
|
|
|
"
|
|
|
|
v-if="!loggedin"
|
|
|
|
/>
|
2024-06-15 15:44:49 +00:00
|
|
|
<!-- <el-button @click="showSecrets = true" v-if="loggedin"> Show secrets </el-button>
|
2024-06-13 05:11:56 +00:00
|
|
|
<el-button @click="showSecrets = false" v-if="showSecrets && loggedin">
|
|
|
|
Hide secrets
|
2024-06-15 15:44:49 +00:00
|
|
|
</el-button> -->
|
2024-06-13 17:02:47 +00:00
|
|
|
<ListSecrets :key="listUpdated" v-if="showSecrets && loggedin" />
|
2024-06-13 05:11:56 +00:00
|
|
|
</div>
|
2024-06-10 15:10:22 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2024-06-11 18:15:29 +00:00
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loggedin: false,
|
2024-06-13 05:11:56 +00:00
|
|
|
showSecrets: false,
|
|
|
|
creationDialog: false,
|
2024-06-13 17:02:47 +00:00
|
|
|
listUpdated: 1,
|
2024-06-14 18:42:02 +00:00
|
|
|
apiBaseUrl: "http://localhost:8000",
|
2024-06-11 18:15:29 +00:00
|
|
|
};
|
|
|
|
},
|
2024-06-13 05:11:56 +00:00
|
|
|
methods: {
|
|
|
|
logout() {
|
2024-06-14 18:42:02 +00:00
|
|
|
sessionStorage.removeItem("token");
|
2024-06-13 05:11:56 +00:00
|
|
|
this.loggedin = false;
|
|
|
|
},
|
2024-06-13 17:02:47 +00:00
|
|
|
|
|
|
|
secretSaved() {
|
|
|
|
this.creationDialog = false;
|
|
|
|
console.log("before update", this.listUpdated);
|
|
|
|
this.listUpdated += 1;
|
|
|
|
console.log("after update", this.listUpdated);
|
|
|
|
},
|
2024-06-14 18:42:02 +00:00
|
|
|
|
|
|
|
async validateToken() {
|
|
|
|
const url = `${this.apiBaseUrl}/validate-token`;
|
|
|
|
const token = sessionStorage.getItem("token");
|
|
|
|
const requestOptions = {
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch(url, requestOptions)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!response) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ("message" in response) {
|
|
|
|
if (response["message"] === "authenticated") {
|
|
|
|
console.log("token validated");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
async mounted() {
|
|
|
|
if ("token" in sessionStorage) {
|
|
|
|
const tokenValid = await this.validateToken();
|
|
|
|
|
|
|
|
if (tokenValid) {
|
|
|
|
this.loggedin = true;
|
|
|
|
this.showSecrets = true;
|
|
|
|
}
|
|
|
|
}
|
2024-06-13 05:11:56 +00:00
|
|
|
},
|
2024-06-11 18:15:29 +00:00
|
|
|
};
|
|
|
|
</script>
|
2024-06-13 05:11:56 +00:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.header {
|
|
|
|
position: absolute;
|
|
|
|
width: 100vw;
|
|
|
|
height: 3rem;
|
|
|
|
padding: 0.3rem;
|
|
|
|
left: 0;
|
|
|
|
top: 0;
|
|
|
|
background-color: aquamarine;
|
|
|
|
}
|
|
|
|
|
|
|
|
.container {
|
|
|
|
margin-top: 2rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.logoutBtn {
|
|
|
|
/* position: relative; */
|
|
|
|
margin-right: 0;
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
.el-page-header__back {
|
|
|
|
display: none !important;
|
|
|
|
}
|
2024-06-15 15:44:49 +00:00
|
|
|
|
|
|
|
#header {
|
|
|
|
width: 100vw;
|
|
|
|
height: 3rem;
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
top: 0;
|
|
|
|
background-color: rgb(170, 247, 247);
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: 0 12px 0 12px;
|
|
|
|
justify-content: space-between;
|
|
|
|
box-shadow: 2px 0px 8px #aaa;
|
|
|
|
}
|
|
|
|
.logo {
|
|
|
|
font-size: 1.3rem;
|
|
|
|
font-weight: 700;
|
|
|
|
}
|
2024-06-13 05:11:56 +00:00
|
|
|
</style>
|