export interface useAuth { authenticate(authCode: string): Promise isAuthenticated(): Promise } export default () => { return { isAuthenticated: async (): Promise => { return $fetch('/api/userinfo') .then(() => true) .catch(() => false) }, authenticate: 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') } }, } }