Next.js Discord

Discord Forum

Is this code likely to cause large initial JS payloads?

Unanswered
Kurilian Bobtail posted this in #help-forum
Open in Discord
Kurilian BobtailOP
I am running into a large JS build issue, here's an example page, i believe the culprit is the checkPermission call

import DomainsList from "@/components/domain/DomainsList";
import { checkPermission } from "utilities/permissions";

export default async function Home() {
  await checkPermission("domain");
  return <DomainsList />;
}


and I'm authing with KINDE and I think this is the culprit and if the users doesn't have the right permissions i redirect them


import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
import { redirect } from "next/navigation";

const getPermissions = async () => {
  const { getPermissions } = getKindeServerSession();
  const permissions = await getPermissions();
  if (!permissions) {
    return [];
  }
  return permissions.permissions;
};

const getUser = async () => {
  const { getUser } = getKindeServerSession();

  return await getUser();
};

const checkPermission = async (
  permission,
  redirectTo = "/?message=noperm",
  type = "push"
) => {
  const permissions = await getPermissions();

  if (!permissions.includes(permission)) {
    redirect(redirectTo, type);
  }
};

export { getPermissions, getUser, checkPermission };

3 Replies

what's the question?
Kurilian BobtailOP
Good point! Is this code likely to cause large initial JS payloads? If so can it be slimmed down?
Sorry about that.