aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/+layout.server.js
blob: ee4c257ebe50c31ff61b94b82afc218d97eff5ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { error, redirect } from '@sveltejs/kit';
import { get, post, auth } from '$lib/utils';
import { env } from '$env/dynamic/public';

export const { PUBLIC_BTC: btc } = env;

export async function load({ cookies, locals, request, url, params }) {
	url.pathname;
	let token = cookies.get('token');
	let rates;
	let subject;

	let { user } = locals;
	if (user) {
		let account = user.accounts.find((a) => a.asset === btc && !a.pubkey);
		if (account) {
			let { id } = account;
			if (user.account_id !== id) {
				user = await post('/shiftAccount', { id }, auth(cookies));
			}
		}
	}

	let rate = await get('/rate');
	rates = await get('/rates');

	return { subject, user, token, rate, rates };
}