Just Launch It

Just
Launch
It

Tutorials Private page

Implementing private and authenticated-only pages are a breeze with Just Launch It since each request contains the user session when authenticated.

Check for a valid user session

By simplying querying the locals object that is injected on every request, you can check whether an active user session exists or not.

/src/routes/dashboard/+layout.server.ts

 1import { redirect } from '@sveltejs/kit';
 2import type { LayoutServerLoad } from './$types';
 3
 4export const load: LayoutServerLoad = async (event) => {
 5	if (!event.locals.user) redirect(302, '/login');
 6
 7	return {
 8		email: event.locals.user.email
 9	};
10};
For your convenience, Just Launch It comes with an authenticated layout server file ready to go in the /src/routes/(authenticated) folder. This makes a perfect place to add your private app pages and keep them organized.