Skip to content

Commit 6932be3

Browse files
committed
fix(getPayloadUser): Throw no serverURL error after cookie statement (#5)
1 parent 294a64f commit 6932be3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/payload/getPayloadUser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ export const getPayloadUser = async <T extends object = User>({
2424
serverUrl = process.env.NEXT_PUBLIC_SERVER_URL,
2525
userCollectionSlug = "users",
2626
}: Options = {}): Promise<T | null> => {
27+
const requestCookies = await cookies();
28+
2729
if (serverUrl === undefined) {
2830
throw new Error(
29-
"getPayloadUser requires a server URL to be provided, either as an option or in the 'NEXT_PUBLIC_SERVER_URL' environment variable",
31+
"getPayloadUser requires a server URL to be provided, either as an option or as the 'NEXT_PUBLIC_SERVER_URL' environment variable",
3032
);
3133
}
3234

33-
const cookieStore = await cookies();
34-
3535
const meUserReq = await fetch(`${serverUrl}/api/${userCollectionSlug}/me`, {
3636
headers: {
37-
Cookie: cookieStore.toString(),
37+
Cookie: requestCookies.toString(),
3838
},
3939
});
4040

0 commit comments

Comments
 (0)