Skip to content

Commit f1885e0

Browse files
authored
fix(nextjs): Comply with Server Actions async requirement (#7445)
1 parent 375a32d commit f1885e0

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

.changeset/pretty-crabs-scream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/nextjs": patch
3+
---
4+
5+
Mark internal keyless header function async to comply with Server Actions async requirements

packages/nextjs/src/__tests__/keyless-custom-headers.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('keyless-custom-headers', () => {
166166
});
167167

168168
describe('formatMetadataHeaders', () => {
169-
it('should format complete metadata object with all fields present', () => {
169+
it('should format complete metadata object with all fields present', async () => {
170170
const metadata = {
171171
nodeVersion: 'v18.17.0',
172172
nextVersion: 'next-server (v15.4.5)',
@@ -181,7 +181,7 @@ describe('keyless-custom-headers', () => {
181181
isCI: false,
182182
};
183183

184-
const result = formatMetadataHeaders(metadata);
184+
const result = await formatMetadataHeaders(metadata);
185185

186186
// Test exact header casing and values
187187
expect(result.get('Clerk-Node-Version')).toBe('v18.17.0');
@@ -196,7 +196,7 @@ describe('keyless-custom-headers', () => {
196196
expect(result.get('Clerk-Auth-Status')).toBe('signed-out');
197197
});
198198

199-
it('should handle missing optional fields gracefully', () => {
199+
it('should handle missing optional fields gracefully', async () => {
200200
const metadata = {
201201
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)',
202202
host: 'localhost:3000',
@@ -208,7 +208,7 @@ describe('keyless-custom-headers', () => {
208208
// Missing: nodeVersion, nextVersion, npmConfigUserAgent, port
209209
};
210210

211-
const result = formatMetadataHeaders(metadata);
211+
const result = await formatMetadataHeaders(metadata);
212212

213213
// Test that only present fields are set
214214
expect(result.get('Clerk-Client-User-Agent')).toBe('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)');
@@ -225,7 +225,7 @@ describe('keyless-custom-headers', () => {
225225
expect(result.get('Clerk-Node-Port')).toBeNull();
226226
});
227227

228-
it('should handle undefined values for optional fields', () => {
228+
it('should handle undefined values for optional fields', async () => {
229229
const metadata = {
230230
nodeVersion: undefined,
231231
nextVersion: undefined,
@@ -240,7 +240,7 @@ describe('keyless-custom-headers', () => {
240240
isCI: false,
241241
};
242242

243-
const result = formatMetadataHeaders(metadata);
243+
const result = await formatMetadataHeaders(metadata);
244244

245245
// Test that undefined fields are not set
246246
expect(result.get('Clerk-Node-Version')).toBeNull();
@@ -257,7 +257,7 @@ describe('keyless-custom-headers', () => {
257257
expect(result.get('Clerk-Auth-Status')).toBe('test-auth-status');
258258
});
259259

260-
it('should handle empty string values', () => {
260+
it('should handle empty string values', async () => {
261261
const metadata = {
262262
nodeVersion: '',
263263
nextVersion: '',
@@ -272,7 +272,7 @@ describe('keyless-custom-headers', () => {
272272
isCI: false,
273273
};
274274

275-
const result = formatMetadataHeaders(metadata);
275+
const result = await formatMetadataHeaders(metadata);
276276

277277
// Empty strings should not be set as headers
278278
expect(result.get('Clerk-Node-Version')).toBeNull();
@@ -513,7 +513,7 @@ describe('keyless-custom-headers', () => {
513513

514514
// Collect metadata and format headers
515515
const metadata = await collectKeylessMetadata();
516-
const headers = formatMetadataHeaders(metadata);
516+
const headers = await formatMetadataHeaders(metadata);
517517

518518
// Verify the full pipeline works correctly
519519
expect(headers.get('Clerk-Client-User-Agent')).toBe('Integration-Test-Agent');

packages/nextjs/src/server/keyless-custom-headers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface MetadataHeaders {
2020
* Collects metadata from the environment and request headers
2121
*/
2222
export async function collectKeylessMetadata(): Promise<MetadataHeaders> {
23-
const headerStore = await headers(); // eslint-disable-line
23+
const headerStore = await headers();
2424

2525
return {
2626
nodeVersion: process.version,
@@ -99,7 +99,7 @@ function getNextVersion(): string | undefined {
9999
/**
100100
* Converts metadata to HTTP headers
101101
*/
102-
export function formatMetadataHeaders(metadata: MetadataHeaders): Headers {
102+
export async function formatMetadataHeaders(metadata: MetadataHeaders): Promise<Headers> {
103103
const headers = new Headers();
104104

105105
if (metadata.nodeVersion) {

0 commit comments

Comments
 (0)