1
+ 'use server' ;
2
+
1
3
import { headers } from 'next/headers' ;
2
4
3
5
interface MetadataHeaders {
4
6
nodeVersion ?: string ;
5
7
nextVersion ?: string ;
6
8
npmConfigUserAgent ?: string ;
7
- userAgent ?: string ;
9
+ userAgent : string ;
10
+ port ?: string ;
11
+ host : string ;
12
+ xHost : string ;
13
+ xPort : string ;
14
+ xProtocol : string ;
15
+ xClerkAuthStatus : string ;
8
16
}
9
17
10
18
/**
@@ -17,7 +25,13 @@ export async function collectKeylessMetadata(): Promise<MetadataHeaders> {
17
25
nodeVersion : process . version ,
18
26
nextVersion : getNextVersion ( ) ,
19
27
npmConfigUserAgent : process . env . npm_config_user_agent , // eslint-disable-line
20
- userAgent : headerStore . get ( 'User-Agent' ) ?? undefined ,
28
+ userAgent : headerStore . get ( 'User-Agent' ) ?? 'unknown user-agent' ,
29
+ port : process . env . PORT , // eslint-disable-line
30
+ host : headerStore . get ( 'host' ) ?? 'unknown host' ,
31
+ xPort : headerStore . get ( 'x-forwarded-port' ) ?? 'unknown x-forwarded-port' ,
32
+ xHost : headerStore . get ( 'x-forwarded-host' ) ?? 'unknown x-forwarded-host' ,
33
+ xProtocol : headerStore . get ( 'x-forwarded-proto' ) ?? 'unknown x-forwarded-proto' ,
34
+ xClerkAuthStatus : headerStore . get ( 'x-clerk-auth-status' ) ?? 'unknown x-clerk-auth-status' ,
21
35
} ;
22
36
}
23
37
@@ -54,5 +68,29 @@ export function formatMetadataHeaders(metadata: MetadataHeaders): Headers {
54
68
headers . set ( 'Clerk-Client-User-Agent' , metadata . userAgent ) ;
55
69
}
56
70
71
+ if ( metadata . port ) {
72
+ headers . set ( 'Clerk-Node-Port' , metadata . port ) ;
73
+ }
74
+
75
+ if ( metadata . host ) {
76
+ headers . set ( 'Clerk-Client-host' , metadata . host ) ;
77
+ }
78
+
79
+ if ( metadata . xPort ) {
80
+ headers . set ( 'Clerk-X-Port' , metadata . xPort ) ;
81
+ }
82
+
83
+ if ( metadata . xHost ) {
84
+ headers . set ( 'Clerk-X-Host' , metadata . xHost ) ;
85
+ }
86
+
87
+ if ( metadata . xProtocol ) {
88
+ headers . set ( 'Clerk-X-protocol' , metadata . xProtocol ) ;
89
+ }
90
+
91
+ if ( metadata . xClerkAuthStatus ) {
92
+ headers . set ( 'Clerk-Auth-Status' , metadata . xClerkAuthStatus ) ;
93
+ }
94
+
57
95
return headers ;
58
96
}
0 commit comments