fix(web): sharing of access token in server API (#1858)

This commit is contained in:
Michel Heusschen
2023-02-24 21:42:20 +01:00
committed by GitHub
parent 3ea107be5a
commit cc6253ba38
14 changed files with 43 additions and 58 deletions

View File

@@ -1,10 +1,9 @@
import { api } from '@api';
import { redirect } from '@sveltejs/kit';
export const prerender = false;
import type { PageLoad } from './$types';
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const load: PageLoad = async () => {
export const load = (async ({ locals: { api } }) => {
try {
const { data: userInfo } = await api.userApi.getMyUserInfo();
@@ -21,4 +20,4 @@ export const load: PageLoad = async () => {
} catch (e) {
throw redirect(302, '/auth/login');
}
};
}) satisfies PageServerLoad;

View File

@@ -1,8 +1,7 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { api } from '@api';
export const load: PageServerLoad = async () => {
export const load = (async ({ locals: { api } }) => {
const { data } = await api.userApi.getUserCount(true);
if (data.userCount === 0) {
// Admin not registered
@@ -14,4 +13,4 @@ export const load: PageServerLoad = async () => {
title: 'Login'
}
};
};
}) satisfies PageServerLoad;

View File

@@ -1,8 +1,7 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { api } from '@api';
export const load: PageServerLoad = async () => {
export const load = (async ({ locals: { api } }) => {
const { data } = await api.userApi.getUserCount(true);
if (data.userCount != 0) {
// Admin has been registered, redirect to login
@@ -14,4 +13,4 @@ export const load: PageServerLoad = async () => {
title: 'Admin Registration'
}
};
};
}) satisfies PageServerLoad;