import { redirect } from '@sveltejs/kit';
import { getStoredClientSession, hasStoredClientSession } from '$lib/session';
import { canOpenReporting, getWorkspaceHomeHref } from '$lib/workspace-access';

export function load() {
  if (!hasStoredClientSession()) {
    return {};
  }

  const session = getStoredClientSession();
  if (session && !canOpenReporting(session)) {
    throw redirect(307, getWorkspaceHomeHref(session));
  }

  return {};
}
