corpushub-design-system 0.0.14 → 0.0.15

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,5 +1,6 @@
1
1
  import { isTransientAuthRefreshError, markApiErrorHandled, } from './apiHandledError';
2
2
  import { clearSession } from '../auth/session';
3
+ import { isPublicAuthRequest } from '../auth/isPublicAuthRequest';
3
4
  import CookieStorage from '../CookieStorage';
4
5
  import { dispatchAccessDeniedError } from './dispatchApiError';
5
6
  import { logged } from '../store/actions';
@@ -58,6 +59,10 @@ export function applyAuthErrorHandling(api, options) {
58
59
  if (status === 401 && isTransientAuthRefreshError(error)) {
59
60
  return Promise.reject(error);
60
61
  }
62
+ // Bad password / missing refresh cookie — let the page show the error.
63
+ if (isPublicAuthRequest(error.config)) {
64
+ return Promise.reject(error);
65
+ }
61
66
  if (authErrorHandling === 'toast') {
62
67
  handleToastAuthError(status, clearSessionOn401);
63
68
  }
@@ -1,5 +1,6 @@
1
1
  import { getAccessToken, refreshAccessTokenOutcome, } from './session';
2
2
  import { markTransientAuthRefresh } from '../api/apiHandledError';
3
+ import { isPublicAuthRequest } from './isPublicAuthRequest';
3
4
  export function installAuthRefreshInterceptor(api) {
4
5
  api.interceptors.response.use((response) => response, async (error) => {
5
6
  const status = error.response?.status;
@@ -7,6 +8,10 @@ export function installAuthRefreshInterceptor(api) {
7
8
  if (status !== 401 || !config || config._retried) {
8
9
  return Promise.reject(error);
9
10
  }
11
+ // Login/refresh/logout 401s are credential failures — do not retry via /refresh.
12
+ if (isPublicAuthRequest(config)) {
13
+ return Promise.reject(error);
14
+ }
10
15
  config._retried = true;
11
16
  const outcome = await refreshAccessTokenOutcome();
12
17
  if (outcome.kind !== 'success') {
@@ -0,0 +1,6 @@
1
+ import type { InternalAxiosRequestConfig } from 'axios';
2
+ /**
3
+ * True when the failed request was itself a public auth call.
4
+ * Used to avoid refresh-retry and session-redirect on login failures.
5
+ */
6
+ export declare function isPublicAuthRequest(config?: InternalAxiosRequestConfig | null): boolean;
@@ -0,0 +1,28 @@
1
+ /** Cookie/password auth endpoints — 401 means bad credentials, not expired access. */
2
+ const PUBLIC_AUTH_PATHS = [
3
+ '/login',
4
+ '/login/google',
5
+ '/refresh',
6
+ '/logout',
7
+ ];
8
+ /**
9
+ * True when the failed request was itself a public auth call.
10
+ * Used to avoid refresh-retry and session-redirect on login failures.
11
+ */
12
+ export function isPublicAuthRequest(config) {
13
+ if (!config) {
14
+ return false;
15
+ }
16
+ const raw = config.url ?? '';
17
+ let path;
18
+ try {
19
+ path = raw.includes('://')
20
+ ? new URL(raw).pathname
21
+ : raw.split('?')[0] ?? '';
22
+ }
23
+ catch {
24
+ path = raw.split('?')[0] ?? '';
25
+ }
26
+ const normalized = path.replace(/\/+$/, '') || '/';
27
+ return PUBLIC_AUTH_PATHS.some((suffix) => normalized === suffix || normalized.endsWith(suffix));
28
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corpushub-design-system",
3
3
  "private": false,
4
- "version": "0.0.14",
4
+ "version": "0.0.15",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {