aboutsummaryrefslogtreecommitdiff
path: root/web/ui/src/routes/+page.server.ts
blob: 2daf03d1be3766dab5c62ec5e63d24546df90e88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { redirect } from '@sveltejs/kit';

import { createAnonymousAccount, createSession } from '$lib/server/auth';
import type { PageServerLoad } from './$types';

/**
 * The root route is just a bouncer: if you already have a session,
 * go to the dashboard; if not, we mint an anonymous account on the
 * spot, set a session cookie, and go to the dashboard.
 *
 * There is intentionally no sign-in page. Users can add an email on
 * the Account tab later if they want a way to recover their keys.
 */
export const load: PageServerLoad = async ({ locals, cookies }) => {
  if (!locals.account) {
    const account = createAnonymousAccount();
    createSession(cookies, account.id);
  }
  throw redirect(303, '/dashboard');
};