@djangocfg/api 2.1.450 → 2.1.453
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/dist/auth.cjs +70 -8
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +105 -2
- package/dist/auth.d.ts +105 -2
- package/dist/auth.mjs +70 -8
- package/dist/auth.mjs.map +1 -1
- package/package.json +4 -2
- package/src/auth/__tests__/authRedirect.test.ts +101 -0
- package/src/auth/__tests__/base64.test.ts +53 -0
- package/src/auth/__tests__/constants.test.ts +30 -0
- package/src/auth/__tests__/formatAuthError.test.ts +48 -0
- package/src/auth/__tests__/guard.test.ts +144 -0
- package/src/auth/__tests__/path.test.ts +67 -0
- package/src/auth/__tests__/profileCache.test.ts +138 -0
- package/src/auth/__tests__/sessionBootstrap.test.ts +35 -0
- package/src/auth/__tests__/useAuthForm.2fa.test.ts +28 -18
- package/src/auth/__tests__/useTokenRefresh.dom.test.tsx +167 -0
- package/src/auth/__tests__/useTwoFactorStatus.test.ts +45 -36
- package/src/auth/__tests__/validation.test.ts +54 -0
- package/src/auth/context/AuthContext.tsx +55 -5
- package/src/auth/hooks/useAutoAuth.ts +5 -17
- package/src/auth/utils/guard.ts +79 -0
- package/src/auth/utils/index.ts +9 -0
- package/src/auth/utils/path.ts +34 -0
package/src/auth/utils/index.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export { validateEmail } from './validation';
|
|
2
2
|
export { formatAuthError } from './errors';
|
|
3
|
+
export {
|
|
4
|
+
resolveGuardIsLoading,
|
|
5
|
+
shouldRedirectToAuth,
|
|
6
|
+
resolveGuardIsAuthenticated,
|
|
7
|
+
nextAuthEvaluationDelay,
|
|
8
|
+
type GuardInput,
|
|
9
|
+
} from './guard';
|
|
10
|
+
export { getTokenExpiry, isTokenExpired, isTokenExpiringSoon } from './jwt';
|
|
11
|
+
export { normalizePath, isAllowedAuthPath } from './path';
|
|
3
12
|
export { logger, authLogger } from './logger';
|
|
4
13
|
export {
|
|
5
14
|
Analytics,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path normalization for auth routing.
|
|
3
|
+
*
|
|
4
|
+
* next-intl may keep a 2-letter locale prefix in the URL (e.g. `/ru/auth`), and
|
|
5
|
+
* paths arrive with or without trailing slashes. To match a pathname against a
|
|
6
|
+
* fixed allow-list (like `['/auth']`) reliably, strip the locale segment and
|
|
7
|
+
* trailing slashes first. Extracted from useAutoAuth so it can be unit-tested
|
|
8
|
+
* and reused.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Strip a leading 2-letter locale segment and trailing slashes.
|
|
13
|
+
* '/ru/auth/' → '/auth', '/auth' → '/auth', '/' → '/', '' → ''.
|
|
14
|
+
*/
|
|
15
|
+
export const normalizePath = (path: string | null | undefined): string => {
|
|
16
|
+
if (!path) return '';
|
|
17
|
+
const withoutLocale = path.replace(/^\/[a-z]{2}(?=\/|$)/, '');
|
|
18
|
+
const trimmed = withoutLocale.replace(/\/+$/, '');
|
|
19
|
+
return trimmed || '/';
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* True when `pathname` (after locale/slash normalization) is one of the allowed
|
|
24
|
+
* paths, or nested under one of them (`/auth` matches `/auth/callback`).
|
|
25
|
+
*/
|
|
26
|
+
export const isAllowedAuthPath = (
|
|
27
|
+
pathname: string | null | undefined,
|
|
28
|
+
allowedPaths: string[],
|
|
29
|
+
): boolean => {
|
|
30
|
+
const normalized = normalizePath(pathname);
|
|
31
|
+
return allowedPaths.some(
|
|
32
|
+
(p) => normalized === p || normalized.startsWith(p + '/'),
|
|
33
|
+
);
|
|
34
|
+
};
|