File tree Expand file tree Collapse file tree
packages/plugins/plugin-auth/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1320,8 +1320,12 @@ export function authEmailLocaleFromRequest(source: unknown): string | undefined
13201320 * context, or anything carrying either. Never throws: a vendor changing the
13211321 * shape it hands a callback must degrade to the deployment default, never fail
13221322 * the send.
1323+ *
1324+ * Exported for `organization-default-currency.ts`, which reads the creating
1325+ * request's language off the endpoint context the same way (#25495): one
1326+ * reader, not two.
13231327 */
1324- function acceptLanguageHeader ( source : unknown ) : string | undefined {
1328+ export function acceptLanguageHeader ( source : unknown ) : string | undefined {
13251329 if ( ! source || typeof source !== 'object' ) return undefined ;
13261330 const nested = ( source as { request ?: unknown } ) . request ;
13271331 const bags = [
Original file line number Diff line number Diff line change 4949import { tryGetCurrentAuthEndpointContext } from '@better-auth/core/context' ;
5050import type { IDataEngine } from '@objectstack/spec/contracts' ;
5151import { preferredLocaleFromHeader , SystemObjectName } from '@objectstack/spec/system' ;
52+ import { acceptLanguageHeader } from './auth-manager.js' ;
5253
5354/**
5455 * Region (ISO 3166-1 alpha-2 and the CLDR territory codes beside it) → the
@@ -204,25 +205,11 @@ export type CreatorLocaleSource = 'the creator\'s stored language' | 'the creati
204205
205206/** The `accept-language` value on the better-auth endpoint context this call runs inside, if any. */
206207function acceptLanguageOfCurrentRequest ( ) : string | undefined {
207- let endpoint : unknown ;
208208 try {
209- endpoint = tryGetCurrentAuthEndpointContext ( ) ;
209+ return acceptLanguageHeader ( tryGetCurrentAuthEndpointContext ( ) ) ;
210210 } catch {
211211 return undefined ;
212212 }
213- if ( ! endpoint || typeof endpoint !== 'object' ) return undefined ;
214- const request = ( endpoint as { request ?: { headers ?: unknown } } ) . request ;
215- for ( const bag of [ ( endpoint as { headers ?: unknown } ) . headers , request ?. headers ] ) {
216- const get = ( bag as { get ?: unknown } | undefined ) ?. get ;
217- if ( typeof get !== 'function' ) continue ;
218- try {
219- const value = ( bag as Headers ) . get ( 'accept-language' ) ;
220- if ( typeof value === 'string' && value ) return value ;
221- } catch {
222- // A header bag that throws on read leaves the request's language unknown.
223- }
224- }
225- return undefined ;
226213}
227214
228215/**
You can’t perform that action at this time.
0 commit comments