allauth/ (44 files) is a django-allauth React UI — a separate concern from the Mizan protocol. Moved to legacy/ pending extraction into a standalone mizan-django-allauth package. Also moved to legacy/: - client/AuthContext.tsx — generic auth state from /me endpoint - client/RouterContext.tsx — framework-agnostic router adapter - client/routing.tsx — UserRoute/StaffRoute/AnonymousRoute guards - client/nextjs.tsx — Next.js router adapter for auth These are auth UI infrastructure, not Mizan protocol. The Mizan core only needs JWT for auth header selection (jwt/ stays — MizanProvider depends on useJWT() to decide between Bearer and session auth). Cleaned up re-exports in client/react.ts and vitest aliases. 33 React tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
214 lines
5.3 KiB
TypeScript
214 lines
5.3 KiB
TypeScript
/**
|
|
* mizan/allauth
|
|
*
|
|
* React integration for django-allauth headless API.
|
|
* Framework-agnostic - works with Next.js, Remix, React Router, etc.
|
|
*
|
|
* ## Quick Start (Next.js)
|
|
*
|
|
* ```tsx
|
|
* // layout.tsx
|
|
* import { cookies } from 'next/headers'
|
|
* import { createDjangoSSRClient } from 'mizan/client'
|
|
* import { getInitialAuth } from 'mizan/allauth'
|
|
* import { NextAllauthContext } from 'mizan/allauth/nextjs'
|
|
*
|
|
* export default async function RootLayout({ children }) {
|
|
* const ssrClient = createDjangoSSRClient({ cookies: await cookies() })
|
|
* const hydration = await getInitialAuth(ssrClient)
|
|
*
|
|
* return (
|
|
* <NextAllauthContext hydration={hydration}>
|
|
* {children}
|
|
* </NextAllauthContext>
|
|
* )
|
|
* }
|
|
* ```
|
|
*
|
|
* ## Without SSR (pure client-side)
|
|
*
|
|
* ```tsx
|
|
* // Just omit hydration - AllauthContext will fetch client-side
|
|
* <NextAllauthContext>
|
|
* {children}
|
|
* </NextAllauthContext>
|
|
* ```
|
|
*/
|
|
|
|
// Configuration
|
|
export { createAllauthConfig, defaultConfig, DjangoFlowPaths } from './config'
|
|
export type { AllauthConfig } from './config'
|
|
|
|
// Hydration
|
|
export { getInitialAuth } from './hydration'
|
|
export type { InitialAuth } from './hydration'
|
|
|
|
// Providers
|
|
export { AllauthContext } from './contexts/AllauthContext'
|
|
export type { AllauthContextProps } from './contexts/AllauthContext'
|
|
|
|
// Router adapter
|
|
export type { RouterAdapter } from './adapters/router'
|
|
export { useRouter } from './contexts/RouterContext'
|
|
|
|
// Hooks
|
|
export { useAuthContext, useAuth, useUser, useConfig, useFeatures } from './contexts/AuthContext'
|
|
export { useAllauthAPI } from './contexts/APIContext'
|
|
export { useAllauthConfig } from './contexts/ConfigContext'
|
|
export { useStyles, cx } from './contexts/StylesContext'
|
|
|
|
// Styling
|
|
export type { AuthClassNames } from './styles/types'
|
|
|
|
// Components
|
|
export {
|
|
// Main UI component (SPA - handles login, signup, MFA, settings, logout)
|
|
AllauthUI,
|
|
// Django-initiated flow handler (email verification, password reset links, OAuth)
|
|
AllauthRouter,
|
|
// Settings
|
|
AuthSettings,
|
|
ProfileSection,
|
|
EmailsSection,
|
|
PasswordSection,
|
|
PasskeysSection,
|
|
ConnectionsSection,
|
|
MFASection,
|
|
SessionsSection,
|
|
SettingsSection,
|
|
SettingsItem,
|
|
SettingsList,
|
|
Badge,
|
|
Button,
|
|
// Individual auth views
|
|
LoginView,
|
|
SignupView,
|
|
MFAChooserView,
|
|
MFAWebAuthnView,
|
|
MFATOTPView,
|
|
MFARecoveryCodesView,
|
|
// Building blocks
|
|
AuthCard,
|
|
AuthFormPage,
|
|
AuthDjangoForm,
|
|
PasskeyLogin,
|
|
ProviderList,
|
|
// Form utilities
|
|
useAuthForm,
|
|
AuthField,
|
|
} from './components'
|
|
export type { AllauthUIView, AllauthUIMode } from './components'
|
|
|
|
// Routing guards
|
|
export { UserRoute, StaffRoute, AnonymousRoute, FeatureRoute } from './routing'
|
|
|
|
// API
|
|
export { createAPI, getAuthDetails } from './api'
|
|
export type { AuthResponse, AuthDetails, AllauthAPI, BrowserFormAction } from './api'
|
|
|
|
// Types (re-exported from types.ts)
|
|
export type {
|
|
// Primitive types
|
|
Timestamp,
|
|
Email,
|
|
Phone,
|
|
Username,
|
|
Password,
|
|
Code,
|
|
AuthenticatorCode,
|
|
ProviderID,
|
|
ProviderAccountID,
|
|
AuthenticatorID,
|
|
ClientID,
|
|
// Enums
|
|
AuthenticatorType as AuthenticatorTypeEnum,
|
|
FlowID,
|
|
LoginMethod,
|
|
OAuthProcess,
|
|
ProviderFlow,
|
|
// User & Session
|
|
User,
|
|
Session,
|
|
EmailAddress,
|
|
PhoneNumber,
|
|
// Authentication
|
|
Flow,
|
|
AuthenticationMethod,
|
|
Authenticated,
|
|
ReauthenticationRequired,
|
|
// Provider
|
|
Provider,
|
|
ProviderAccount,
|
|
// MFA / Authenticator
|
|
BaseAuthenticator,
|
|
TOTPAuthenticator,
|
|
RecoveryCodesAuthenticator,
|
|
SensitiveRecoveryCodesAuthenticator,
|
|
WebAuthnAuthenticator,
|
|
Authenticator,
|
|
// Configuration
|
|
AccountConfiguration,
|
|
SocialAccountConfiguration,
|
|
MFAConfiguration,
|
|
UserSessionsConfiguration,
|
|
AllauthConfiguration,
|
|
// WebAuthn
|
|
WebAuthnPublicKeyCredentialCreationOptions,
|
|
WebAuthnPublicKeyCredentialRequestOptions,
|
|
WebAuthnCreationOptions,
|
|
WebAuthnRequestOptions,
|
|
// TOTP
|
|
TOTPStatus,
|
|
// Meta
|
|
BaseAuthenticationMeta,
|
|
AuthenticationMeta,
|
|
AuthenticatedMeta,
|
|
// Response types
|
|
AuthError,
|
|
AllauthResponse,
|
|
AuthenticatedResponse,
|
|
ConfigurationResponse,
|
|
EmailListResponse,
|
|
SessionListResponse,
|
|
AuthenticatorListResponse,
|
|
ProviderAccountListResponse,
|
|
TOTPStatusResponse,
|
|
RecoveryCodesResponse,
|
|
WebAuthnCreationOptionsResponse,
|
|
WebAuthnRequestOptionsResponse,
|
|
EmailVerificationInfoResponse,
|
|
AuthenticationRequiredResponse,
|
|
ReauthenticationRequiredResponse,
|
|
ErrorResponse,
|
|
ForbiddenResponse,
|
|
ConflictResponse,
|
|
SessionGoneResponse,
|
|
// Request types
|
|
LoginRequest,
|
|
SignupRequest,
|
|
ProviderSignupRequest,
|
|
ReauthenticateRequest,
|
|
RequestLoginCodeRequest,
|
|
ConfirmLoginCodeRequest,
|
|
MFAAuthenticateRequest,
|
|
MFATrustRequest,
|
|
RequestPasswordResetRequest,
|
|
ResetPasswordRequest,
|
|
VerifyEmailRequest,
|
|
ChangePasswordRequest,
|
|
AddEmailRequest,
|
|
ProviderRedirectRequest,
|
|
ProviderTokenRequest,
|
|
WebAuthnAddRequest,
|
|
WebAuthnAuthenticateRequest,
|
|
WebAuthnUpdateRequest,
|
|
WebAuthnDeleteRequest,
|
|
EndSessionsRequest,
|
|
// Union types
|
|
AuthResponse as AuthResponseUnion,
|
|
SessionStatusResponse,
|
|
} from './types'
|
|
|
|
// Constants
|
|
export { Flows, AuthenticatorType } from './defines'
|