FastAuth/frontend/src/components/ListSecrets.vue

95 lines
2.4 KiB
Vue
Raw Normal View History

2024-06-11 18:15:29 +00:00
<template>
<div>
<el-table :data="secretsList" style="width: 100vw">
2024-06-13 17:54:48 +00:00
<el-table-column type="expand">
<template #default="props">
<div style="margin-left: 3rem">
{{ props.row.notes }}
</div>
</template>
</el-table-column>
<el-table-column prop="id" label="Id" />
<el-table-column prop="issuer" label="Issuer" />
<el-table-column prop="username" label="Username" />
<el-table-column label="Secret">
<template #default="scope">
<div>
{{ generateTotp(scope.row.secret) }}
</div>
</template>
</el-table-column>
2024-06-13 17:54:48 +00:00
<!-- <el-table-column prop="notes" label="Notes" /> -->
<el-table-column fixed="right" label="Operations" width="120">
<template #default="scope">
<el-button link type="primary" size="small" @click="handleClick(scope)">
Edit
</el-button>
</template>
</el-table-column>
</el-table>
</div>
2024-06-11 18:15:29 +00:00
</template>
<script>
import { TOTP } from "totp-generator";
2024-06-11 18:15:29 +00:00
export default {
data() {
return {
message: "Hello List Secret",
apiBaseUrl: "http://localhost:8000",
secretsList: [],
2024-06-11 18:15:29 +00:00
};
},
methods: {
async listSecrets() {
const url = `${this.apiBaseUrl}/secret`;
const token = localStorage.getItem("token");
const requestOptions = {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
};
console.log(requestOptions);
const response = await fetch(url, requestOptions)
.then((response) => response.json())
.then((data) => {
2024-06-13 17:54:48 +00:00
console.log(data);
return data;
})
.catch((err) => console.log(err));
response.forEach((element) => {
2024-06-13 17:54:48 +00:00
// console.log(element);
const row = this.parseSecret(element.data);
2024-06-13 17:54:48 +00:00
row["id"] = element["id"];
this.secretsList.push(row);
});
},
parseSecret(gibberish) {
const jsonString = atob(gibberish);
const secret = JSON.parse(jsonString);
return secret;
},
generateTotp(secret) {
const { otp, expires } = TOTP.generate(secret);
console.log(expires);
return otp;
},
2024-06-13 17:54:48 +00:00
handleClick(scope) {
console.log(scope);
},
},
mounted() {
this.listSecrets();
},
2024-06-11 18:15:29 +00:00
};
</script>