@djangocfg/api 2.1.547 → 2.1.548

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.d.cts CHANGED
@@ -1232,7 +1232,9 @@ declare const formatAuthError: (error: unknown) => string;
1232
1232
  *
1233
1233
  * Invariant that fixes the bug: once auth is resolved (`authLoading === false`)
1234
1234
  * and the user is unauthenticated, `isLoading` must become false so the guard
1235
- * redirects to the form instead of spinning forever.
1235
+ * redirects to the form instead of spinning forever. The same invariant covers
1236
+ * the forbidden case: a signed-in user without the required privilege must stop
1237
+ * loading too, or the preloader spins on a state no redirect will ever clear.
1236
1238
  */
1237
1239
  interface GuardInput {
1238
1240
  /** First client render matches SSR (preloader) until mounted, to avoid hydration mismatch. */
@@ -1245,7 +1247,20 @@ interface GuardInput {
1245
1247
  isRedirecting: boolean;
1246
1248
  /** User currently has a (valid-looking) session. */
1247
1249
  isAuthenticated: boolean;
1250
+ /** Route requires staff/admin privileges, not just a session. */
1251
+ requireStaff?: boolean;
1252
+ /** `is_staff || is_superuser`, from `useAuth().isAdminUser`. */
1253
+ isAdminUser?: boolean;
1248
1254
  }
1255
+ /**
1256
+ * True when the session is valid but lacks the required privilege.
1257
+ *
1258
+ * Distinct from unauthenticated: the fix is a different account, not signing
1259
+ * in, so this must never redirect to the auth form. Redirecting would also
1260
+ * loop — the guard saves the current URL first, so a successful re-login on
1261
+ * the same account returns straight to the wall.
1262
+ */
1263
+ declare function isForbidden(s: GuardInput): boolean;
1249
1264
  /**
1250
1265
  * True while the guard should render a preloader rather than the protected
1251
1266
  * content. Mirrors useAuthGuard's formula exactly.
@@ -1355,4 +1370,4 @@ declare const Analytics: {
1355
1370
  setUser(userId: string | null): void;
1356
1371
  };
1357
1372
 
1358
- export { AUTH_CONSTANTS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestConsent, type OTPRequestResult, type PasswordLoginOptions, type PasswordLoginResult, type PatchedCfgUserUpdateRequest, PatchedCfgUserUpdateRequestSchema, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, logger, normalizePath, peekSavedRedirect, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
1373
+ export { AUTH_CONSTANTS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestConsent, type OTPRequestResult, type PasswordLoginOptions, type PasswordLoginResult, type PatchedCfgUserUpdateRequest, PatchedCfgUserUpdateRequestSchema, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, isForbidden, logger, normalizePath, peekSavedRedirect, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
package/dist/auth.d.ts CHANGED
@@ -1232,7 +1232,9 @@ declare const formatAuthError: (error: unknown) => string;
1232
1232
  *
1233
1233
  * Invariant that fixes the bug: once auth is resolved (`authLoading === false`)
1234
1234
  * and the user is unauthenticated, `isLoading` must become false so the guard
1235
- * redirects to the form instead of spinning forever.
1235
+ * redirects to the form instead of spinning forever. The same invariant covers
1236
+ * the forbidden case: a signed-in user without the required privilege must stop
1237
+ * loading too, or the preloader spins on a state no redirect will ever clear.
1236
1238
  */
1237
1239
  interface GuardInput {
1238
1240
  /** First client render matches SSR (preloader) until mounted, to avoid hydration mismatch. */
@@ -1245,7 +1247,20 @@ interface GuardInput {
1245
1247
  isRedirecting: boolean;
1246
1248
  /** User currently has a (valid-looking) session. */
1247
1249
  isAuthenticated: boolean;
1250
+ /** Route requires staff/admin privileges, not just a session. */
1251
+ requireStaff?: boolean;
1252
+ /** `is_staff || is_superuser`, from `useAuth().isAdminUser`. */
1253
+ isAdminUser?: boolean;
1248
1254
  }
1255
+ /**
1256
+ * True when the session is valid but lacks the required privilege.
1257
+ *
1258
+ * Distinct from unauthenticated: the fix is a different account, not signing
1259
+ * in, so this must never redirect to the auth form. Redirecting would also
1260
+ * loop — the guard saves the current URL first, so a successful re-login on
1261
+ * the same account returns straight to the wall.
1262
+ */
1263
+ declare function isForbidden(s: GuardInput): boolean;
1249
1264
  /**
1250
1265
  * True while the guard should render a preloader rather than the protected
1251
1266
  * content. Mirrors useAuthGuard's formula exactly.
@@ -1355,4 +1370,4 @@ declare const Analytics: {
1355
1370
  setUser(userId: string | null): void;
1356
1371
  };
1357
1372
 
1358
- export { AUTH_CONSTANTS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestConsent, type OTPRequestResult, type PasswordLoginOptions, type PasswordLoginResult, type PatchedCfgUserUpdateRequest, PatchedCfgUserUpdateRequestSchema, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, logger, normalizePath, peekSavedRedirect, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
1373
+ export { AUTH_CONSTANTS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestConsent, type OTPRequestResult, type PasswordLoginOptions, type PasswordLoginResult, type PatchedCfgUserUpdateRequest, PatchedCfgUserUpdateRequestSchema, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, isForbidden, logger, normalizePath, peekSavedRedirect, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
package/dist/auth.mjs CHANGED
@@ -5147,9 +5147,16 @@ var formatAuthError = /* @__PURE__ */ __name((error) => {
5147
5147
  }, "formatAuthError");
5148
5148
 
5149
5149
  // src/auth/utils/guard.ts
5150
+ function isForbidden(s) {
5151
+ return Boolean(
5152
+ s.mounted && s.requireAuth && s.requireStaff && !s.authLoading && s.isAuthenticated && !s.isAdminUser
5153
+ );
5154
+ }
5155
+ __name(isForbidden, "isForbidden");
5150
5156
  function resolveGuardIsLoading(s) {
5151
5157
  if (!s.mounted) return true;
5152
5158
  if (!s.requireAuth) return false;
5159
+ if (isForbidden(s)) return false;
5153
5160
  return s.authLoading || s.isRedirecting || !s.isAuthenticated;
5154
5161
  }
5155
5162
  __name(resolveGuardIsLoading, "resolveGuardIsLoading");
@@ -5180,6 +5187,7 @@ export {
5180
5187
  getCachedProfile,
5181
5188
  hasValidCache,
5182
5189
  isAllowedAuthPath,
5190
+ isForbidden,
5183
5191
  logger,
5184
5192
  normalizePath,
5185
5193
  peekSavedRedirect,