@djangocfg/api 2.1.483 → 2.1.484

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/api",
3
- "version": "2.1.483",
3
+ "version": "2.1.484",
4
4
  "description": "Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends",
5
5
  "keywords": [
6
6
  "django",
@@ -84,7 +84,7 @@
84
84
  "zod": "^4.3.6"
85
85
  },
86
86
  "devDependencies": {
87
- "@djangocfg/typescript-config": "^2.1.483",
87
+ "@djangocfg/typescript-config": "^2.1.484",
88
88
  "@testing-library/react": "^16.3.2",
89
89
  "@types/node": "^25.9.5",
90
90
  "@types/react": "19.2.15",
@@ -30,6 +30,25 @@ import { PatchedCfgUserUpdateRequestSchema } from '../../_api/generated/_cfg_acc
30
30
  import { clearProfileCache, getCachedProfile, setCachedProfile } from '../hooks/useProfileCache';
31
31
  import { authLogger } from '../utils/logger';
32
32
 
33
+ /**
34
+ * Whether this build has a usable API origin.
35
+ *
36
+ * `NEXT_PUBLIC_API_URL` is inlined at build time; when it is missing the
37
+ * generated client falls back to `''`, and every request becomes relative to
38
+ * whatever page the user is on. A static build is same-origin by design, so
39
+ * relative paths ARE correct there.
40
+ */
41
+ function hasApiOrigin(): boolean {
42
+ try {
43
+ if (typeof process === 'undefined' || !process.env) return false;
44
+ if (process.env.NEXT_PUBLIC_STATIC_BUILD === 'true') return true;
45
+ if (process.env.NEXT_PUBLIC_API_PROXY_URL !== undefined) return true;
46
+ return Boolean(process.env.NEXT_PUBLIC_API_URL);
47
+ } catch {
48
+ return false;
49
+ }
50
+ }
51
+
33
52
  import type {
34
53
  User,
35
54
  CfgUserUpdateRequest,
@@ -96,6 +115,15 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
96
115
  const refreshProfile = useCallback(async (options?: { callerId?: string; force?: boolean }): Promise<User | undefined> => {
97
116
  const { callerId, force } = options || {};
98
117
 
118
+ // No API origin configured → skip the request instead of letting it resolve
119
+ // against the current page. A relative URL on an i18n-prefixed route turns
120
+ // `/cfg/accounts/profile` into `/<locale>/cfg/accounts/profile` on the
121
+ // site's own origin — a 404 that only ever shows up in production.
122
+ if (!hasApiOrigin()) {
123
+ authLogger.debug(`No API origin configured, skipping profile fetch (caller: ${callerId})`);
124
+ return undefined;
125
+ }
126
+
99
127
  if (isLoadingRef.current) {
100
128
  authLogger.debug(`Profile loading in progress, skipping (caller: ${callerId})`);
101
129
  return profileRef.current;