diff --git a/client/src/components/LoginBox.vue b/client/src/components/LoginBox.vue index 69a13be..53c2dc2 100644 --- a/client/src/components/LoginBox.vue +++ b/client/src/components/LoginBox.vue @@ -10,26 +10,32 @@ diff --git a/client/src/composables/useAuth.ts b/client/src/composables/useAuth.ts new file mode 100644 index 0000000..447078b --- /dev/null +++ b/client/src/composables/useAuth.ts @@ -0,0 +1,26 @@ +import { useMyselfStore } from '~~/src/stores/MyselfStore' + +export interface useAuth { + validate(): Promise + setAuthCode(authCode: string): void +} + + +export default () => { + const MyselfStore = useMyselfStore() + + return { + validate: async (): Promise => { + if (MyselfStore.authCode.length != 6) { + throw Error('login failed') + } + const resp = await $fetch(`/api/login?code=${MyselfStore.authCode}`) + if (resp !== 'ok') { + throw Error('login failed') + } + }, + setAuthCode: (authCode: string): void => { + MyselfStore.setAuthCode(authCode) + } + } +} diff --git a/client/src/stores/MyselfStore.ts b/client/src/stores/MyselfStore.ts new file mode 100644 index 0000000..193f43d --- /dev/null +++ b/client/src/stores/MyselfStore.ts @@ -0,0 +1,14 @@ +import { defineStore } from 'pinia' + +export const useMyselfStore = defineStore('MyselfStore', { + state: () => { + return { + authCode: '', + } + }, + actions: { + setAuthCode(authCode: string): void { + this.authCode = authCode + } + }, +})