wip trpc
This commit is contained in:
39
apps/client/src/routes/+layout.ts
Normal file
39
apps/client/src/routes/+layout.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { t } from '$lib/store';
|
||||
import type { LayoutLoad } from './$types';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import Cookies from 'js-cookie';
|
||||
export const ssr = false;
|
||||
|
||||
export const load: LayoutLoad = async ({ url }) => {
|
||||
const { pathname } = new URL(url);
|
||||
const baseSettings = await t.settings.getBaseSettings.query();
|
||||
try {
|
||||
if (pathname === '/login' || pathname === '/register') {
|
||||
return {
|
||||
...baseSettings
|
||||
};
|
||||
}
|
||||
const settings = await t.settings.getInstanceSettings.query();
|
||||
if (settings.data.token) {
|
||||
Cookies.set('token', settings.data.token);
|
||||
}
|
||||
return {
|
||||
...baseSettings,
|
||||
...settings
|
||||
};
|
||||
} catch (err) {
|
||||
if (err?.data?.httpStatus == 401) {
|
||||
throw redirect(307, '/login');
|
||||
}
|
||||
if (err instanceof Error) {
|
||||
throw error(500, {
|
||||
message: 'An unexpected error occurred, please try again later.' + '<br><br>' + err.message
|
||||
});
|
||||
}
|
||||
|
||||
throw error(500, {
|
||||
message: 'An unexpected error occurred, please try again later.'
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user