1
0
Fork 0
forked from TWS/kalkutago

Move logOut function into method on state

This commit is contained in:
D. Scott Boggs 2023-08-26 07:03:16 -04:00
parent 003383e455
commit dafdd491f9
2 changed files with 9 additions and 8 deletions

View file

@ -1,15 +1,8 @@
<script setup lang="ts">
import { RouterLink } from 'vue-router';
import { error } from '../error'
import router from "../router";
import { state } from '../state'
async function logOut() {
const result = await fetch('/api/v1/auth', {method: 'DELETE'})
if(!result.ok) return error('failed to log out')
state.user = undefined
router.push('/login')
}
</script>
<template>
<nav class="navbar" role="navigation" aria-label="main navigation">
@ -32,7 +25,7 @@ async function logOut() {
</RouterLink>
</div>
<div class="navbar-item">
<button class="button is-info" @click="logOut">
<button class="button is-info" @click="state.logOut()">
Log Out
</button>
</div>

View file

@ -3,6 +3,7 @@ import { Track } from "./track"
import { Tick } from './ticks'
import { error } from "./error"
import { getCookie } from "./util";
import router from './router'
enum State {
Unfetched,
@ -130,6 +131,13 @@ class AppState {
const response = await fetch(`/api/v1/tracks/${trackID}`, { method: "DELETE" })
if (!response.ok) error(`error deleting track with ID ${trackID}: ${response.statusText} (${response.status})`)
}
async logOut() {
const result = await fetch('/api/v1/auth', {method: 'DELETE'})
if(!result.ok) return error('failed to log out')
this.user = undefined
router.push('/login')
}
}
export const state = reactive(new AppState)