fileserver/frontend/src/App.vue

59 lines
1002 B
Vue
Raw Normal View History

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