import { redirect } from '@sveltejs/kit';
import { pb } from '$lib/pb';

export const ssr = false;

export function load({ url }) {
	const isLoginPage = url.pathname === '/admin/login';
	if (!pb.authStore.isValid && !isLoginPage) {
		throw redirect(303, '/admin/login');
	}
	if (pb.authStore.isValid && isLoginPage) {
		throw redirect(303, '/admin/dashboard');
	}
}
