@mundogamernetwork/shared-ui 1.1.34 → 1.1.36

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.
@@ -1,7 +1,6 @@
1
1
  export default defineNuxtPlugin({
2
2
  name: "shared-ui-auth",
3
3
  enforce: "pre",
4
- parallel: true,
5
4
  async setup() {
6
5
  try {
7
6
  const authStore = useAuthStore();
@@ -40,11 +40,12 @@ export function getHttpService(): AxiosInstance {
40
40
  _httpService.interceptors.response.use(
41
41
  (response) => response,
42
42
  (error) => {
43
+ const url: string = error.config?.url ?? "";
44
+ // The auth/user (or /users/me) probe is the canonical session check.
45
+ const isAuthProbe = /\/auth\/user(\?|$)|\/users\/me(\?|$)/.test(url);
46
+
43
47
  if (typeof window !== "undefined" && error?.response) {
44
48
  const status = error.response.status;
45
- const url: string = error.config?.url ?? "";
46
- // The auth/user (or /users/me) probe is the canonical session check.
47
- const isAuthProbe = /\/auth\/user(\?|$)|\/users\/me(\?|$)/.test(url);
48
49
 
49
50
  // 401 on the auth probe = the session is genuinely gone (expired/invalid
50
51
  // token). Clear the stale credentials so the loop breaks and the user
@@ -66,6 +67,14 @@ export function getHttpService(): AxiosInstance {
66
67
  console.error(`[HTTP] Error ${status}:`, error.response?.data?.message || "");
67
68
  }
68
69
  }
70
+
71
+ // A stale auth cookie can make the API fatal before CORS headers are
72
+ // rendered. Axios reports that as ERR_NETWORK, so clear auth only when
73
+ // the failed request was the canonical auth probe.
74
+ if (typeof window !== "undefined" && !error?.response && isAuthProbe) {
75
+ recoverFromSessionLoss();
76
+ }
77
+
69
78
  return Promise.reject(error);
70
79
  },
71
80
  );
@@ -85,14 +94,6 @@ export function getHttpService(): AxiosInstance {
85
94
  config.headers.set("X-Timezone", Intl.DateTimeFormat().resolvedOptions().timeZone);
86
95
  }
87
96
 
88
- // Live Analytics: send current page route and platform ID so the
89
- // GeoAnalyticsMiddleware on each service-api can record session activity.
90
- if (typeof window !== "undefined") {
91
- config.headers.set("X-Page-Route", window.location.pathname);
92
- const systemId = import.meta.env.VITE_SYSTEM_ID;
93
- if (systemId) config.headers.set("X-System-Id", String(systemId));
94
- }
95
-
96
97
  return config;
97
98
  });
98
99
 
@@ -72,28 +72,16 @@ export const useAppInstallBannerStore = defineStore("app-install-banner-store",
72
72
  }),
73
73
 
74
74
  actions: {
75
- async fetchBanner(overrideBaseUrl?: string, overridePlatformId?: number) {
75
+ async fetchBanner() {
76
76
  if (this.loaded) return;
77
77
 
78
78
  const runtimeConfig = useRuntimeConfig();
79
- const cfg = runtimeConfig.public;
80
- // Priority: explicit props from layout > shared-ui namespace > flat runtimeConfig keys > build-time env vars
81
79
  const networkBaseUrl =
82
- overrideBaseUrl ||
83
- cfg.mgSharedUi?.networkBaseUrl ||
84
- cfg.networkBaseURL ||
85
- cfg.networkBaseUrl ||
86
- cfg.apiBaseURL ||
87
- (import.meta.env.VITE_BASE_URL_NETWORK as string) ||
88
- (import.meta.env.VITE_API_BASE_URL as string);
89
- const platformId =
90
- overridePlatformId ||
91
- Number(
92
- cfg.mgSharedUi?.systemId ||
93
- cfg.platformId ||
94
- cfg.systemId ||
95
- import.meta.env.VITE_SYSTEM_ID,
96
- );
80
+ runtimeConfig.public.mgSharedUi?.networkBaseUrl ||
81
+ import.meta.env.VITE_BASE_URL_NETWORK;
82
+ const platformId = Number(
83
+ runtimeConfig.public.mgSharedUi?.systemId || import.meta.env.VITE_SYSTEM_ID,
84
+ );
97
85
 
98
86
  if (!networkBaseUrl || !platformId) {
99
87
  this.loaded = true;
@@ -131,12 +119,8 @@ export const useAppInstallBannerStore = defineStore("app-install-banner-store",
131
119
 
132
120
  dismiss() {
133
121
  const runtimeConfig = useRuntimeConfig();
134
- const cfg = runtimeConfig.public;
135
122
  const platformId = Number(
136
- cfg.mgSharedUi?.systemId ||
137
- cfg.platformId ||
138
- cfg.systemId ||
139
- import.meta.env.VITE_SYSTEM_ID,
123
+ runtimeConfig.public.mgSharedUi?.systemId || import.meta.env.VITE_SYSTEM_ID,
140
124
  );
141
125
  if (platformId) writeDismiss(platformId);
142
126
  this.dismissed = true;