SolidJSS
SolidJSโ€ข15mo agoโ€ข
2 replies
Ho-kage

Action triggering revalidation without cookie

I am implementing an admin site which uses BetterAuth. When implementing an action it seems it tries to fetch fresh data (my createAsync call) but it fails my admin validation because the cookie doesn't seem to be present. Not quite sure how I get around this. The isAdmin function is shown below (it gets called by functions in a "use server" context).

import { getRequestEvent } from "solid-js/web";
import { auth } from "./auth";

export async function isAdmin() {
  const event = getRequestEvent();

  if (!event) {
    return false;
  }

  console.log(event.request.headers.get("cookie"));
  const session = await auth.api.getSession({ headers: event.request.headers });

  if (!session) {
    return false;
  }

  if (!session.session.userId) {
    return false;
  }

  if (session.user.role !== "admin") {
    return false;
  }

  return true;
}
Was this page helpful?