UNPKG

payload-authjs

Version:
23 lines (22 loc) 877 B
import { cookies } from "next/headers"; /** * Get the payload user from the server (only works on the server side) * * @deprecated Use `getPayloadSession` instead */ export const getPayloadUser = async ({ serverUrl = process.env.NEXT_PUBLIC_SERVER_URL, userCollectionSlug = "users" } = {})=>{ const requestCookies = await cookies(); if (serverUrl === undefined) { throw new Error("getPayloadUser requires a server URL to be provided, either as an option or as the 'NEXT_PUBLIC_SERVER_URL' environment variable"); } const meUserReq = await fetch(`${serverUrl}/api/${userCollectionSlug}/me`, { headers: { Cookie: requestCookies.toString() } }); const { user } = await meUserReq.json(); if (!meUserReq.ok || !user) { return undefined; } return user; }; //# sourceMappingURL=getPayloadUser.js.map