added logout and removed stamps that arent mine

This commit is contained in:
2025-12-10 01:42:22 +00:00
parent 9a0c054968
commit 2ac72d1fd0
4 changed files with 32 additions and 26 deletions

View File

@@ -10,17 +10,23 @@ const loggedIn = computed(() => !!auth.user.username);
function handleLogin() { function handleLogin() {
auth.logIn(username.value, password.value); auth.logIn(username.value, password.value);
} }
function handleLogout() {
auth.logOut();
}
</script> </script>
<template> <template>
<div v-if="loggedIn"> <div v-if="loggedIn">
<h1>Logged in</h1>
<p>{{ auth.user.ID }}</p> <p>{{ auth.user.ID }}</p>
<p>{{ auth.user.username }}</p> <p>{{ auth.user.username }}</p>
<button @click="handleLogout">Log Out</button>
</div> </div>
<div v-else> <div v-else>
<h1>login</h1> <h1>Login</h1>
<textarea v-model="username"></textarea> <input type="text" v-model="username" placeholder="Username" />
<textarea type="password" v-model="password"></textarea> <input type="password" v-model="password" placeholder="Password" />
<button @click="handleLogin">Log In</button> <button @click="handleLogin">Log In</button>
</div> </div>
</template> </template>

View File

@@ -1,22 +1,10 @@
<template> <template>
<div> <div>
<RouterLink to="/cv"> <RouterLink to="/cv">
<img src="/img/stamps/BC7BDBB9-36FF-4DBE-B825-3603BFE00BE0.gif" /> <h1>CV</h1>
</RouterLink> </RouterLink>
<RouterLink to="/admin"> <RouterLink to="/admin">
<img src="/img/stamps/BC7BDBB9-36FF-4DBE-B825-3603BFE00BE0.gif" /> <h1>ADMIN</h1>
</RouterLink>
<RouterLink to="/admin">
<img src="/img/stamps/BC7BDBB9-36FF-4DBE-B825-3603BFE00BE0.gif" />
</RouterLink>
<RouterLink to="/admin">
<img src="/img/stamps/BC7BDBB9-36FF-4DBE-B825-3603BFE00BE0.gif" />
</RouterLink>
<RouterLink to="/admin">
<img src="/img/stamps/BC7BDBB9-36FF-4DBE-B825-3603BFE00BE0.gif" />
</RouterLink>
<RouterLink to="/admin">
<img src="/img/stamps/BC7BDBB9-36FF-4DBE-B825-3603BFE00BE0.gif" />
</RouterLink> </RouterLink>
</div> </div>
</template> </template>

View File

@@ -1,14 +1,9 @@
<template> <template>
<div class="flex-row"> <div class="flex-row">
<div> <div>
<img src="/img/stamps/12351B56-A370-465D-A951-739A480A05EC.gif" /> <!-- <img src="/img/stamps/12351B56-A370-465D-A951-739A480A05EC.gif" />
<img src="/img/stamps/71663263-8E08-4873-8EE1-96DC342C57EB.gif" /> <img src="/img/stamps/71663263-8E08-4873-8EE1-96DC342C57EB.gif" />
<img src="/img/stamps/8a0014c1.gif" /> <img src="/img/stamps/8a0014c1.gif" /> -->
</div>
<div>
<img src="/img/stamps/BC7BDBB9-36FF-4DBE-B825-3603BFE00BE0.gif" />
<img src="/img/stamps/BC7BDBB9-36FF-4DBE-B825-3603BFE00BE0.gif" />
<img src="/img/stamps/BC7BDBB9-36FF-4DBE-B825-3603BFE00BE0.gif" />
</div> </div>
</div> </div>
</template> </template>

View File

@@ -6,7 +6,12 @@ export const useAuthStore = defineStore("auth", () => {
const user = ref({}); const user = ref({});
checkToken(); checkToken();
function logOut() { async function logOut() {
try {
const res = await axios.post("/api/auth/logout");
} catch (err) {
console.error(err);
}
user.value = {}; user.value = {};
} }
@@ -22,6 +27,18 @@ export const useAuthStore = defineStore("auth", () => {
} }
} }
async function createUser(username, password) {
try {
const res = await axios.post("/api/user", {
username,
password,
});
user.value = res.data;
} catch (err) {
console.error(err);
}
}
async function refreshToken() { async function refreshToken() {
try { try {
const res = await axios.post("/api/auth/refresh"); const res = await axios.post("/api/auth/refresh");
@@ -40,5 +57,5 @@ export const useAuthStore = defineStore("auth", () => {
} }
} }
return { user, checkToken, logIn, refreshToken, logOut }; return { user, checkToken, logIn, refreshToken, logOut, createUser };
}); });