diff --git a/src/pages/account/index.vue b/src/pages/account/index.vue index 569d1ee..bfdcd1f 100644 --- a/src/pages/account/index.vue +++ b/src/pages/account/index.vue @@ -5,7 +5,8 @@ definePageMeta({ needsAuth: true }); -const { data: profile } = await useApiFetch('/api/auth/me', { }); +const authStore = useAuthStore(); +const { data: profile, refresh } = await useApiFetch('/api/auth/me', { }); async function updateServerEnvironment(env: ApiAccountUpdateRequest['environment']) { try { @@ -15,6 +16,7 @@ async function updateServerEnvironment(env: ApiAccountUpdateRequest['environment environment: env } satisfies ApiAccountUpdateRequest }); + await refresh(); } catch (error: unknown) { const err = getApiError(error); alert(err.code); @@ -26,6 +28,8 @@ async function deleteAccount() { await apiFetch('/api/account/delete', { method: 'POST' }); + authStore.logout(); + await navigateTo('/'); } catch (error: unknown) { const err = getApiError(error); alert(err.code); diff --git a/src/pages/account/register/index.vue b/src/pages/account/register/index.vue index 198ea61..80ec30e 100644 --- a/src/pages/account/register/index.vue +++ b/src/pages/account/register/index.vue @@ -3,6 +3,7 @@ import VueHcaptcha from '@hcaptcha/vue3-hcaptcha'; import type { ApiAuthRegisterRequest } from '~~/shared/api-types'; const route = useRoute(); +const auth = useAuthStore(); const redirect = computed(() => route.query.redirect); const loginURI = computed(() => `/account/login${redirect.value ? `?redirect=${redirect.value}` : ''}`); @@ -15,7 +16,7 @@ async function registerSubmission() { try { const hCaptchaResponse = invisibleHcaptcha.value ? (await invisibleHcaptcha.value.executeAsync()).response : null; - await $fetch('/api/auth/register', { + const res = await $fetch('/api/auth/register', { method: 'POST', body: { email: registerForm.email, @@ -25,6 +26,10 @@ async function registerSubmission() { captchaResponse: hCaptchaResponse ?? undefined } satisfies ApiAuthRegisterRequest }); + auth.set({ + accessToken: res.accessToken, + refreshToken: res.refreshToken + }); if (typeof redirect.value === 'string') { await navigateTo(redirect.value);