fileserver/frontend/src/App.vue

63 lines
1.2 KiB
Vue
Raw Normal View History

2022-08-17 19:59:51 +00:00
<script setup async lang="ts">
2022-08-31 12:28:35 +00:00
import { provide, ref } from "vue";
import { useRouter } from "vue-router";
import type { TokenInjectType } from "@/api";
2022-08-17 19:59:51 +00:00
const router = useRouter();
2022-08-31 12:28:35 +00:00
const jwt = ref<string | null>(localStorage.getItem("token"));
2022-08-17 19:59:51 +00:00
function setToken(token: string) {
2022-08-31 12:28:35 +00:00
jwt.value = token;
localStorage.setItem("token", token);
2022-08-17 19:59:51 +00:00
}
function logout() {
2022-08-31 12:28:35 +00:00
jwt.value = null;
localStorage.removeItem("token");
router.push({ name: "login" });
2022-08-17 19:59:51 +00:00
}
2022-08-31 12:28:35 +00:00
provide<TokenInjectType>("jwt", {
jwt,
setToken,
logout,
2022-08-17 19:59:51 +00:00
});
</script>
<template>
2022-08-31 12:28:35 +00:00
<nav>
<template v-if="jwt != null">
<router-link to="/">Files</router-link>
<span style="margin-left: 2em" />
<router-link to="/profile">Profile</router-link>
<span style="margin-left: 2em" />
<router-link to="/login" @click="logout()">Logout</router-link>
</template>
</nav>
<router-view />
2022-08-17 19:59:51 +00:00
</template>
<style lang="scss">
#app {
2022-08-31 12:28:35 +00:00
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
2022-08-17 19:59:51 +00:00
}
nav {
2022-08-31 12:28:35 +00:00
padding: 30px;
2022-08-17 19:59:51 +00:00
2022-08-31 12:28:35 +00:00
a {
font-weight: bold;
color: #2c3e50;
2022-08-17 19:59:51 +00:00
2022-08-31 12:28:35 +00:00
&.router-link-exact-active {
color: #42b983;
}
}
2022-08-17 19:59:51 +00:00
}
</style>