import { redirect } from "@sveltejs/kit";
import { isModel } from "$lib/api";
import { getAnalytics } from "$lib/services";

export async function load({ locals, fetch, cookies }) {
  if (!isModel(locals.authStatus.user!)) {
    throw redirect(302, "/me/profile");
  }
  const token = cookies.get("session_token") || "";
  return {
    analytics: await getAnalytics(fetch, token).catch(() => null),
  };
}
