mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-08-22 16:47:16 -05:00
feat: implement login after register
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user