Move logOut function into method on state
This commit is contained in:
parent
003383e455
commit
dafdd491f9
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue