Auth client in Next server actions - always getting 401

Hi!

I'm trying to use the auth client in a next server action, but any api I hit on the server side is always unauthorized. Is there some way to configure the auth client with the user's server-side session?

I know I can do auth.api.doThing but I'd greatly prefer to use the auth client for the sake of consistency.

Also, I know I can run these on the client, but there is a very specific reason this specific call is on the server.

const myServerAction = () => {
  // i have the authorized session
  const session = auth.api.getSession({ headers: await getHeaders() });
  // always 401's, but only on the server.  any way to pass/configure the session?
  const { data, error } = await authClient.organization.create({
    // ...args
  });
}
Was this page helpful?