feat: implement login after register

This commit is contained in:
mrjvs
2026-08-12 13:35:28 +02:00
parent cd1ba7c8f0
commit 43e734bf21
2 changed files with 11 additions and 2 deletions

View File

@@ -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);

View File

@@ -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);