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

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

  const session = getStoredClientSession();
  if (!session) {
    return {};
  }

  if (!canOpenSettings(session)) {
    throw redirect(307, getWorkspaceHomeHref(session));
  }

  return {};
}
