export interface useAuth { login(authCode: string): Promise logout(): Promise isAuthenticated(): Promise } export default () => { return { isAuthenticated: async (): Promise => { return $fetch('/api/userinfo') .then(() => true) .catch(() => false) }, login: async (authCode: string): Promise => { if (authCode.length != 6) { throw Error('login failed') } const resp = await $fetch(`/api/login?code=${authCode}`) if (resp !== 'ok') { throw Error('login failed') } }, logout: async (): Promise => { await $fetch('/api/logout') }, } }