doct-ui-auth-kit 1.0.12 → 1.0.14
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/adapters/http-auth-adapter.d.ts +13 -0
- package/dist/adapters/index.d.ts +1 -0
- package/dist/auth/index.d.ts +28 -0
- package/dist/auth-methods/apple.d.ts +19 -0
- package/dist/auth-methods/google.d.ts +5 -0
- package/dist/auth-methods/index.d.ts +2 -0
- package/dist/auth-methods/use-google-auth.d.ts +69 -0
- package/dist/components/common/back-button.d.ts +13 -0
- package/dist/components/common/default-footer.d.ts +5 -0
- package/dist/components/common/enterprise-header.d.ts +22 -0
- package/dist/components/common/index.d.ts +3 -0
- package/dist/components/form/rhf-doct-phone-input.d.ts +2 -0
- package/dist/components/form/rhf-input-field.d.ts +2 -0
- package/dist/components/form/rhf-otp-input-field.d.ts +3 -0
- package/dist/components/layout/auth-layout-preset.d.ts +30 -0
- package/dist/components/layout/auth-layout-public.d.ts +17 -0
- package/dist/components/layout/auth-layout-wrapper.d.ts +42 -0
- package/dist/components/layout/auth-layout.d.ts +89 -0
- package/dist/components/layout/image-slider.d.ts +28 -0
- package/dist/components/layout/index.d.ts +8 -0
- package/dist/components/layout/main-layout.d.ts +30 -0
- package/dist/constants/brand.d.ts +9 -0
- package/dist/constants/demo-slider.d.ts +14 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/layout-classes.d.ts +10 -0
- package/dist/constants/layout-presets.d.ts +10 -0
- package/dist/core/auth-api-adapter.d.ts +6 -0
- package/dist/core/auth-context.d.ts +21 -0
- package/dist/core/auth-flow.d.ts +35 -0
- package/dist/core/auth-provider.d.ts +8 -0
- package/dist/core/auth-types.d.ts +5 -0
- package/dist/core/device-detection.d.ts +19 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/sso-session.d.ts +35 -0
- package/dist/core/use-auth-flow-router-sync.d.ts +28 -0
- package/dist/core/use-auth-flow.d.ts +9 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/use-login-entry-form.d.ts +12 -0
- package/dist/hooks/use-main-auth-page-handlers.d.ts +9 -0
- package/dist/hooks/use-otp-verification.d.ts +15 -0
- package/dist/hooks/use-repeat-login.d.ts +9 -0
- package/dist/hooks/use-signup-form.d.ts +12 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +1364 -1346
- package/dist/pages/index.d.ts +8 -0
- package/dist/pages/login-entry/index.d.ts +3 -0
- package/dist/pages/login-entry/login-entry-page.d.ts +21 -0
- package/dist/pages/login-entry/login-entry.d.ts +21 -0
- package/dist/pages/main-login/index.d.ts +3 -0
- package/dist/pages/main-login/main-login-page.d.ts +16 -0
- package/dist/pages/main-login/main-login.d.ts +25 -0
- package/dist/pages/otp-verification/index.d.ts +3 -0
- package/dist/pages/otp-verification/otp-verification-page.d.ts +23 -0
- package/dist/pages/otp-verification/otp-verification.d.ts +22 -0
- package/dist/pages/repeat-login/index.d.ts +3 -0
- package/dist/pages/repeat-login/repeat-login-page.d.ts +24 -0
- package/dist/pages/repeat-login/repeat-login.d.ts +25 -0
- package/dist/pages/signup/index.d.ts +3 -0
- package/dist/pages/signup/signup-page.d.ts +6 -0
- package/dist/pages/signup/signup.d.ts +7 -0
- package/dist/pages.js +1 -1
- package/dist/signup-page-ChXnxtSS.js +1683 -0
- package/dist/types/auth/auth-api-adapter.d.ts +57 -0
- package/dist/types/auth/auth-provider.d.ts +40 -0
- package/dist/types/auth/auth-types.d.ts +70 -0
- package/dist/types/auth/device-detection.d.ts +13 -0
- package/dist/types/auth/flow.d.ts +127 -0
- package/dist/types/auth/index.d.ts +10 -0
- package/dist/types/auth/router.d.ts +60 -0
- package/dist/types/auth/sso-session.d.ts +33 -0
- package/dist/types/components/auth-layout-types.d.ts +92 -0
- package/dist/types/components/forms.d.ts +77 -0
- package/dist/types/components/index.d.ts +7 -0
- package/dist/types/components/layout-presets.d.ts +29 -0
- package/dist/types/components/layout.d.ts +57 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/pages/index.d.ts +9 -0
- package/dist/types/pages/login-form.d.ts +57 -0
- package/dist/types/pages/main-login.d.ts +51 -0
- package/dist/types/pages/otp-verification.d.ts +53 -0
- package/dist/types/pages/pages.d.ts +146 -0
- package/dist/types/pages/repeat-login.d.ts +29 -0
- package/dist/types/pages/signup-form.d.ts +49 -0
- package/dist/utils/build-phone-recipient.d.ts +12 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/set-form-errors-from-zod.d.ts +11 -0
- package/dist/validations/index.d.ts +6 -0
- package/dist/validations/schemas.d.ts +87 -0
- package/package.json +9 -5
- package/dist/signup-page-x-C4j5YV.js +0 -1629
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/** Props for the ImageSlider component. */
|
|
3
|
+
export interface ImageSliderProps {
|
|
4
|
+
/** Array of image URLs to display */
|
|
5
|
+
images: string[];
|
|
6
|
+
/** Auto-play interval in milliseconds (0 to disable) */
|
|
7
|
+
autoPlayInterval?: number;
|
|
8
|
+
/** Additional className for the root container */
|
|
9
|
+
className?: string;
|
|
10
|
+
/** Whether to hide the built-in slider indicators */
|
|
11
|
+
hideIndicators?: boolean;
|
|
12
|
+
/** Optional callback fired whenever the active slide changes */
|
|
13
|
+
onSlideChange?: (index: number) => void;
|
|
14
|
+
/** Controlled active index (makes component controlled) */
|
|
15
|
+
activeIndex?: number;
|
|
16
|
+
/** Callback for manual slide navigation in controlled mode */
|
|
17
|
+
onNavigate?: (index: number) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Props for the MainLayout component.
|
|
21
|
+
* Two-panel auth page: left panel (marketing/slider), right panel (auth content).
|
|
22
|
+
*/
|
|
23
|
+
export interface MainLayoutProps {
|
|
24
|
+
/** Array of image URLs for the slider */
|
|
25
|
+
sliderImages?: string[];
|
|
26
|
+
/** Auto-play interval for slider in milliseconds (0 to disable) */
|
|
27
|
+
sliderAutoPlayInterval?: number;
|
|
28
|
+
/** Call-to-action text displayed above the image card. Set to null to hide */
|
|
29
|
+
ctaText?: ReactNode | null;
|
|
30
|
+
/** Per-slide title/CTA (overrides ctaText when provided; uses active slide index) */
|
|
31
|
+
sliderTitles?: (ReactNode | string)[] | undefined;
|
|
32
|
+
/** Additional className for the root container */
|
|
33
|
+
className?: string;
|
|
34
|
+
/** Additional className for the marketing panel (left side) */
|
|
35
|
+
marketingClassName?: string;
|
|
36
|
+
/** Additional className for the content panel (right side) */
|
|
37
|
+
contentClassName?: string;
|
|
38
|
+
/** Main authentication content (typically AuthLayout.Root with slots) */
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
}
|
|
41
|
+
/** Props for the MarketingPanel component (left side). */
|
|
42
|
+
export interface MarketingPanelProps {
|
|
43
|
+
/** Array of image URLs for the slider */
|
|
44
|
+
sliderImages: string[];
|
|
45
|
+
/** Auto-play interval for slider in milliseconds */
|
|
46
|
+
sliderAutoPlayInterval: number;
|
|
47
|
+
/** Active slide index (controlled) */
|
|
48
|
+
activeSlideIndex: number;
|
|
49
|
+
/** Callback when slide changes */
|
|
50
|
+
onSlideChange: (index: number) => void;
|
|
51
|
+
/** Call-to-action text */
|
|
52
|
+
ctaText?: ReactNode | null;
|
|
53
|
+
/** Per-slide title/CTA (overrides ctaText when provided) */
|
|
54
|
+
sliderTitles?: (ReactNode | string)[] | undefined;
|
|
55
|
+
/** Additional className */
|
|
56
|
+
className?: string;
|
|
57
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-specific types: props, form values, hook options/return types.
|
|
3
|
+
*/
|
|
4
|
+
export * from './login-form';
|
|
5
|
+
export * from './main-login';
|
|
6
|
+
export * from './otp-verification';
|
|
7
|
+
export * from './pages';
|
|
8
|
+
export * from './repeat-login';
|
|
9
|
+
export * from './signup-form';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { loginEmailFormSchema, loginPhoneFormSchema } from '../../validations';
|
|
4
|
+
/** Login mode: phone number or email */
|
|
5
|
+
export type LoginEntryMode = 'phone' | 'email';
|
|
6
|
+
/** Form values for phone-based login, inferred from the Zod schema. */
|
|
7
|
+
export type PhoneFormValues = z.infer<typeof loginPhoneFormSchema>;
|
|
8
|
+
/** Form values for email-based login, inferred from the Zod schema. */
|
|
9
|
+
export type EmailFormValues = z.infer<typeof loginEmailFormSchema>;
|
|
10
|
+
/** Discriminated union of phone or email login form values. */
|
|
11
|
+
export type LoginEntryFormValues = PhoneFormValues | EmailFormValues;
|
|
12
|
+
/** Payload when login entry form is valid (phone or email). */
|
|
13
|
+
export type LoginEntrySubmitData = {
|
|
14
|
+
phone?: string;
|
|
15
|
+
email?: string;
|
|
16
|
+
countryCode?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Params passed to onSuccess after submitApi resolves.
|
|
20
|
+
* Lets the consumer redirect to OTP with mode and recipient (for recipientDisplay) without storing them in refs.
|
|
21
|
+
*/
|
|
22
|
+
export interface LoginEntrySuccessParams {
|
|
23
|
+
/** Current login entry mode (phone or email). */
|
|
24
|
+
mode: LoginEntryMode;
|
|
25
|
+
/** Submitted phone or email string; use for OTP page recipientDisplay or verify API. */
|
|
26
|
+
recipient: string;
|
|
27
|
+
}
|
|
28
|
+
export interface UseLoginEntryFormOptions {
|
|
29
|
+
mode: LoginEntryMode;
|
|
30
|
+
/**
|
|
31
|
+
* Sync callback with valid form data. Used when parent owns API (e.g. AuthFlow passes actions.submitIdentifier).
|
|
32
|
+
* Ignored when submitApi is provided.
|
|
33
|
+
*/
|
|
34
|
+
onSubmit?: ((data: LoginEntrySubmitData) => void) | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* When provided, hook runs business logic: validate → call submitApi(data) → onSuccess(params).
|
|
37
|
+
* Use from consumer (e.g. Next.js): submitApi = sendOtp, onSuccess = (params) => router.push(`/otp?mode=${params.mode}&recipient=${encodeURIComponent(params.recipient)}`).
|
|
38
|
+
*/
|
|
39
|
+
submitApi?: ((data: LoginEntrySubmitData) => Promise<void>) | undefined;
|
|
40
|
+
/** Called after submitApi resolves successfully; receives mode and recipient for OTP redirect/display. */
|
|
41
|
+
onSuccess?: ((params: LoginEntrySuccessParams) => void) | undefined;
|
|
42
|
+
/** Called when submitApi rejects or throws. */
|
|
43
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
44
|
+
}
|
|
45
|
+
/** Return value of the `useLoginEntryForm` hook, providing form state and mode info. */
|
|
46
|
+
export interface UseLoginEntryFormReturn {
|
|
47
|
+
/** react-hook-form methods bound to the current login mode's schema. */
|
|
48
|
+
methods: UseFormReturn<LoginEntryFormValues>;
|
|
49
|
+
/** Submit handler to pass to the form's `onSubmit`. Validates and dispatches the login data. */
|
|
50
|
+
handleSubmit: (data: LoginEntryFormValues) => void;
|
|
51
|
+
/** True when the current mode is `'phone'`; use for conditional field rendering. */
|
|
52
|
+
isPhone: boolean;
|
|
53
|
+
/** True when current form values pass validation (for disabling Continue until valid – edge cases 3, 4). */
|
|
54
|
+
isFormValid: (data: LoginEntryFormValues) => boolean;
|
|
55
|
+
/** True while submitApi is in flight. Use to disable Continue button and show loading. */
|
|
56
|
+
isSubmitting: boolean;
|
|
57
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Handlers exposed by the main auth page (method select). */
|
|
2
|
+
export interface MainAuthPageHandlers {
|
|
3
|
+
/** Called when the user selects "Continue with Mobile". */
|
|
4
|
+
onContinueWithMobile: () => void;
|
|
5
|
+
/** Called when the user selects "Continue with Email". */
|
|
6
|
+
onContinueWithEmail: () => void;
|
|
7
|
+
/** Called when the user selects "Continue with Google". */
|
|
8
|
+
onContinueWithGoogle: () => void;
|
|
9
|
+
/** Called when the user selects "Continue with Apple". */
|
|
10
|
+
onContinueWithApple: () => void;
|
|
11
|
+
}
|
|
12
|
+
/** Config for lib-handled Google sign-in. When set, the lib runs the OAuth flow and calls onCredential. */
|
|
13
|
+
export interface MainLoginGoogleProviderConfig {
|
|
14
|
+
/** Google OAuth 2.0 client ID. */
|
|
15
|
+
clientId: string;
|
|
16
|
+
/** Called with ID token (One Tap) or auth code (button popup). Send to your backend to verify. */
|
|
17
|
+
onCredential: (credential: string) => void;
|
|
18
|
+
/** Enable Google One Tap prompt for automatic sign-in. */
|
|
19
|
+
enableOneTap?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Config for lib-handled Apple sign-in (stub). When set, the lib will run the flow and call onCredential when implemented. */
|
|
22
|
+
export interface MainLoginAppleProviderConfig {
|
|
23
|
+
/** Apple Services ID (client ID) configured in the Apple Developer portal. */
|
|
24
|
+
clientId: string;
|
|
25
|
+
/** OAuth redirect URI registered with Apple for the sign-in flow. */
|
|
26
|
+
redirectUri: string;
|
|
27
|
+
/** Called with the Apple identity token after a successful sign-in. Send to your backend to verify. */
|
|
28
|
+
onCredential: (credential: string) => void;
|
|
29
|
+
}
|
|
30
|
+
/** Optional provider config so the lib handles Google/Apple API calls. */
|
|
31
|
+
export interface MainLoginPageProvidersConfig {
|
|
32
|
+
/** Google sign-in configuration. When set, the lib handles the Google OAuth flow. */
|
|
33
|
+
google?: MainLoginGoogleProviderConfig;
|
|
34
|
+
/** Apple sign-in configuration. When set, the lib handles the Apple OAuth flow. */
|
|
35
|
+
apple?: MainLoginAppleProviderConfig;
|
|
36
|
+
}
|
|
37
|
+
/** Options for useMainAuthPageHandlers: optional callback overrides + optional provider config for lib-handled OAuth. */
|
|
38
|
+
export type UseMainAuthPageHandlersOptions = Partial<MainAuthPageHandlers> & {
|
|
39
|
+
providers?: MainLoginPageProvidersConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Custom handler for the "Enterprise Login" header CTA. When omitted,
|
|
42
|
+
* the header redirects to the default enterprise URL
|
|
43
|
+
* (`DEFAULT_ENTERPRISE_LOGIN_URL`).
|
|
44
|
+
*/
|
|
45
|
+
onEnterpriseLogin?: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Override the default enterprise redirect URL. Ignored when
|
|
48
|
+
* `onEnterpriseLogin` is provided. Defaults to `https://docthub.com/`.
|
|
49
|
+
*/
|
|
50
|
+
enterpriseLoginUrl?: string;
|
|
51
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { OtpVerificationMode, otpFormSchema } from '../../validations';
|
|
4
|
+
export type { OtpVerificationMode };
|
|
5
|
+
/** Form values for the OTP verification form, inferred from the Zod schema. */
|
|
6
|
+
export type OtpFormValues = z.infer<typeof otpFormSchema>;
|
|
7
|
+
/**
|
|
8
|
+
* Consumer-provided custom validator for OTP. Runs after the built-in
|
|
9
|
+
* 6-digit check passes. Return `true` to accept, or a string message to
|
|
10
|
+
* surface as the field error (and block submission). May be async so
|
|
11
|
+
* callers can hit a backend pre-check before the full verify call.
|
|
12
|
+
*/
|
|
13
|
+
export type OtpValidateFn = (otp: string) => string | true | Promise<string | true>;
|
|
14
|
+
/** Options for the `useOtpVerification` hook controlling mode, submission, and callbacks. */
|
|
15
|
+
export interface UseOtpVerificationOptions {
|
|
16
|
+
/** OTP mode: phone (60s cooldown) or email (2 min cooldown). */
|
|
17
|
+
mode: OtpVerificationMode;
|
|
18
|
+
/** Sync callback with OTP string. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
|
|
19
|
+
onSubmit?: ((otp: string) => void) | undefined;
|
|
20
|
+
/** Called when the user requests a new OTP code (resend). Ignored when submitApi is provided. */
|
|
21
|
+
onResendCode?: (() => void) | undefined;
|
|
22
|
+
/** When provided, hook runs: validate → submitApi(otp) → onSuccess(). Consumer passes redirect in onSuccess. */
|
|
23
|
+
submitApi?: ((otp: string) => Promise<void>) | undefined;
|
|
24
|
+
/** Called after submitApi resolves (e.g. router.push('/dashboard')). */
|
|
25
|
+
onSuccess?: (() => void) | undefined;
|
|
26
|
+
/** Called when submitApi rejects or throws. */
|
|
27
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Optional custom OTP validator. Runs after the built-in digit check.
|
|
30
|
+
* Return `true` to accept, or a string to surface as the field error
|
|
31
|
+
* and block submission.
|
|
32
|
+
*/
|
|
33
|
+
validate?: OtpValidateFn | undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Return value of the `useOtpVerification` hook, providing form state and resend controls. */
|
|
36
|
+
export interface UseOtpVerificationReturn {
|
|
37
|
+
/** react-hook-form methods bound to the OTP form. */
|
|
38
|
+
methods: UseFormReturn<OtpFormValues>;
|
|
39
|
+
/** Submit handler to pass to the form's `onSubmit`. Validates and dispatches the OTP. */
|
|
40
|
+
handleSubmit: (data: OtpFormValues) => void;
|
|
41
|
+
/** True when current form values pass validation (for disabling Submit until valid – edge case 6). */
|
|
42
|
+
isFormValid: (data: OtpFormValues) => boolean;
|
|
43
|
+
/** Triggers a resend of the OTP code and resets the cooldown timer. */
|
|
44
|
+
handleResend: () => void;
|
|
45
|
+
/** Seconds remaining before the user can request another OTP code. */
|
|
46
|
+
resendSecondsLeft: number;
|
|
47
|
+
/** True when the resend cooldown has elapsed and the user may request a new code. */
|
|
48
|
+
canResend: boolean;
|
|
49
|
+
/** Human-readable countdown string (e.g. `"00:45"`) for display next to the resend button. */
|
|
50
|
+
timerText: string;
|
|
51
|
+
/** True while submitApi is in flight. */
|
|
52
|
+
isSubmitting: boolean;
|
|
53
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props and public types for auth page components.
|
|
3
|
+
*/
|
|
4
|
+
import type { UserType } from '../auth/auth-types';
|
|
5
|
+
import type { IdentifierType } from '../auth/flow';
|
|
6
|
+
import type { LoginEntryMode } from './login-form';
|
|
7
|
+
import type { UseMainAuthPageHandlersOptions } from './main-login';
|
|
8
|
+
import type { OtpValidateFn, OtpVerificationMode } from './otp-verification';
|
|
9
|
+
/** Props for MainLoginPage and MainLogin components. */
|
|
10
|
+
export type MainLoginPageProps = UseMainAuthPageHandlersOptions;
|
|
11
|
+
/** Props for LoginEntry (inner form without layout). */
|
|
12
|
+
export interface LoginEntryProps {
|
|
13
|
+
/** Mode: phone number or email input */
|
|
14
|
+
mode: LoginEntryMode;
|
|
15
|
+
/** Override title (consumers render via AuthLayout.Title) */
|
|
16
|
+
title?: string;
|
|
17
|
+
/** Override subtitle (consumers render via AuthLayout.Description) */
|
|
18
|
+
subtitle?: string;
|
|
19
|
+
/** Handler when back button is clicked (consumers render back button in AuthLayout.Logo) */
|
|
20
|
+
onBack?: () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Sync callback with valid data. Use when parent owns API (e.g. AuthFlow).
|
|
23
|
+
* Ignored when submitApi is provided.
|
|
24
|
+
*/
|
|
25
|
+
onSubmit?: ((data: {
|
|
26
|
+
phone?: string;
|
|
27
|
+
email?: string;
|
|
28
|
+
countryCode?: string;
|
|
29
|
+
}) => void) | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Async API call (e.g. send OTP). When provided, hook runs: validate → submitApi(data) → onSuccess().
|
|
32
|
+
* Consumer (e.g. Next.js) can pass redirect in onSuccess.
|
|
33
|
+
*/
|
|
34
|
+
submitApi?: ((data: {
|
|
35
|
+
phone?: string;
|
|
36
|
+
email?: string;
|
|
37
|
+
countryCode?: string;
|
|
38
|
+
}) => Promise<void>) | undefined;
|
|
39
|
+
/** Called after submitApi succeeds; receives { mode, recipient } for OTP redirect/recipientDisplay. */
|
|
40
|
+
onSuccess?: ((params: {
|
|
41
|
+
mode: LoginEntryMode;
|
|
42
|
+
recipient: string;
|
|
43
|
+
}) => void) | undefined;
|
|
44
|
+
/** Called when submitApi fails. */
|
|
45
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
46
|
+
}
|
|
47
|
+
/** Props for the full LoginEntryPage (adds optional layout overrides for story/viewport). */
|
|
48
|
+
export interface LoginEntryPageProps extends LoginEntryProps {
|
|
49
|
+
/** Layout type. Default: 'withSlider' for desktop, use 'standalone' for mobile. */
|
|
50
|
+
layoutType?: 'withSlider' | 'standalone';
|
|
51
|
+
/** Layout variant. Default derived from layoutType if not set. */
|
|
52
|
+
variant?: 'desktop' | 'mobile';
|
|
53
|
+
}
|
|
54
|
+
/** Props for Signup (inner form without layout). */
|
|
55
|
+
export interface SignupPageProps {
|
|
56
|
+
/** Indian: which field to collect. Foreign: use 'foreign' mode (name + email + phone). */
|
|
57
|
+
userType: UserType;
|
|
58
|
+
/** How user started (phone or email). */
|
|
59
|
+
loginMethod: IdentifierType;
|
|
60
|
+
/** Indian only: which field to collect (phone or email). */
|
|
61
|
+
signupCollectField: IdentifierType;
|
|
62
|
+
/** Foreign only: phone when user entered phone before signup details. */
|
|
63
|
+
pendingPhone?: string | undefined;
|
|
64
|
+
/** Sync callback with valid data. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
|
|
65
|
+
onSubmit?: ((data: {
|
|
66
|
+
fullName: string;
|
|
67
|
+
phone?: string;
|
|
68
|
+
email?: string;
|
|
69
|
+
countryCode?: string;
|
|
70
|
+
}) => void) | undefined;
|
|
71
|
+
/** Async API (e.g. complete profile). When provided, hook runs: validate → submitApi(data) → onSuccess(). */
|
|
72
|
+
submitApi?: ((data: {
|
|
73
|
+
fullName: string;
|
|
74
|
+
phone?: string;
|
|
75
|
+
email?: string;
|
|
76
|
+
countryCode?: string;
|
|
77
|
+
}) => Promise<void>) | undefined;
|
|
78
|
+
/** Called after submitApi succeeds (e.g. router.push('/otp') or next step). */
|
|
79
|
+
onSuccess?: (() => void) | undefined;
|
|
80
|
+
/** Called when submitApi fails. */
|
|
81
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
82
|
+
}
|
|
83
|
+
/** Props for the full SignupPage (adds optional layout overrides). */
|
|
84
|
+
export interface SignupPageFullProps extends SignupPageProps {
|
|
85
|
+
layoutType?: 'withSlider' | 'standalone';
|
|
86
|
+
variant?: 'desktop' | 'mobile';
|
|
87
|
+
}
|
|
88
|
+
/** Props for OtpVerification (inner form without layout). */
|
|
89
|
+
export interface OtpVerificationProps {
|
|
90
|
+
/** Mode: mobile (phone) or email OTP */
|
|
91
|
+
mode: OtpVerificationMode;
|
|
92
|
+
/** Title override. Default: "6 digit OTP has been sent to your Mobile" | "..." Email */
|
|
93
|
+
title?: string | undefined;
|
|
94
|
+
/** Masked phone (e.g. "+91 9825910X0X") or email (e.g. "j***@gmail.com") */
|
|
95
|
+
recipientDisplay: string;
|
|
96
|
+
/** When true, show instruction line ("Kindly check your Email Inbox."). Used for foreign user flow. */
|
|
97
|
+
isForeignUser?: boolean | undefined;
|
|
98
|
+
/** Handler when back is clicked */
|
|
99
|
+
onBack?: (() => void) | undefined;
|
|
100
|
+
/** Sync callback with OTP. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
|
|
101
|
+
onSubmit?: ((otp: string) => void) | undefined;
|
|
102
|
+
/** Handler when user requests resend code */
|
|
103
|
+
onResendCode?: (() => void) | undefined;
|
|
104
|
+
/** Async API (e.g. verify OTP). When provided, hook runs: validate → submitApi(otp) → onSuccess(). */
|
|
105
|
+
submitApi?: ((otp: string) => Promise<void>) | undefined;
|
|
106
|
+
/** Called after submitApi succeeds (e.g. router.push('/dashboard')). */
|
|
107
|
+
onSuccess?: (() => void) | undefined;
|
|
108
|
+
/** Called when submitApi fails. */
|
|
109
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Optional custom OTP validator. Runs after the built-in 6-digit
|
|
112
|
+
* check; return `true` to accept or a string message to display as
|
|
113
|
+
* the field error (and block submission).
|
|
114
|
+
*/
|
|
115
|
+
validate?: OtpValidateFn | undefined;
|
|
116
|
+
}
|
|
117
|
+
/** Props for the full OtpVerificationPage (adds optional layout overrides). */
|
|
118
|
+
export interface OtpVerificationPageProps extends OtpVerificationProps {
|
|
119
|
+
layoutType?: 'withSlider' | 'standalone';
|
|
120
|
+
variant?: 'desktop' | 'mobile';
|
|
121
|
+
}
|
|
122
|
+
/** Props for RepeatLogin (inner component without layout). */
|
|
123
|
+
export interface RepeatLoginProps {
|
|
124
|
+
/**
|
|
125
|
+
* Last used authentication method shown in the primary button label.
|
|
126
|
+
* Example: "Mobile", "Email".
|
|
127
|
+
*
|
|
128
|
+
* @default "Mobile"
|
|
129
|
+
*/
|
|
130
|
+
lastUsedMethod?: string;
|
|
131
|
+
/** Sync handler for primary action. Use when caller owns API (e.g. AuthFlow). Ignored when continueApi is provided. */
|
|
132
|
+
onContinueWithLastMethod?: (() => void) | undefined;
|
|
133
|
+
/** Handler for the secondary action (choose another method). */
|
|
134
|
+
onUseAnotherMethod?: (() => void) | undefined;
|
|
135
|
+
/** Async API for continue (e.g. validate session). When provided, hook runs: continueApi() → onSuccess(). */
|
|
136
|
+
continueApi?: (() => Promise<void>) | undefined;
|
|
137
|
+
/** Called after continueApi succeeds (e.g. router.push('/dashboard')). */
|
|
138
|
+
onSuccess?: (() => void) | undefined;
|
|
139
|
+
/** Called when continueApi fails. */
|
|
140
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
141
|
+
}
|
|
142
|
+
/** Props for the full RepeatLoginPage (adds optional layout overrides). */
|
|
143
|
+
export interface RepeatLoginPageProps extends RepeatLoginProps {
|
|
144
|
+
layoutType?: 'withSlider' | 'standalone';
|
|
145
|
+
variant?: 'desktop' | 'mobile';
|
|
146
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook options and return type for repeat login (continue with last method).
|
|
3
|
+
*/
|
|
4
|
+
export interface UseRepeatLoginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Last used authentication method shown in the primary button label.
|
|
7
|
+
* @default "Mobile"
|
|
8
|
+
*/
|
|
9
|
+
lastUsedMethod?: string | undefined;
|
|
10
|
+
/** Sync handler for primary action. Use when caller owns API (e.g. AuthFlow). Ignored when continueApi is provided. */
|
|
11
|
+
onContinueWithLastMethod?: (() => void) | undefined;
|
|
12
|
+
/** Handler for the secondary action (choose another method). */
|
|
13
|
+
onUseAnotherMethod?: (() => void) | undefined;
|
|
14
|
+
/** Async API for continue (e.g. validate session). When provided, hook runs: continueApi() → onSuccess(). */
|
|
15
|
+
continueApi?: (() => Promise<void>) | undefined;
|
|
16
|
+
/** Called after continueApi succeeds (e.g. router.push('/dashboard')). */
|
|
17
|
+
onSuccess?: (() => void) | undefined;
|
|
18
|
+
/** Called when continueApi fails. */
|
|
19
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** Return value of the `useRepeatLogin` hook, providing continue handler and display state. */
|
|
22
|
+
export interface UseRepeatLoginReturn {
|
|
23
|
+
/** Call this when the user clicks "Continue with {lastUsedMethod}". */
|
|
24
|
+
handleContinue: () => void;
|
|
25
|
+
/** True while continueApi is in flight. */
|
|
26
|
+
isSubmitting: boolean;
|
|
27
|
+
/** Resolved lastUsedMethod for display (default "Mobile"). */
|
|
28
|
+
lastUsedMethod: string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { signupEmailFormSchema, signupForeignFormSchema, signupPhoneFormSchema } from '../../validations';
|
|
4
|
+
/** Signup mode: phone, email as second field, or foreign (full name + email + phone). */
|
|
5
|
+
export type SignupEntryMode = 'phone' | 'email' | 'foreign';
|
|
6
|
+
/** Form values for phone-based signup, inferred from the Zod schema. */
|
|
7
|
+
export type SignupPhoneFormValues = z.infer<typeof signupPhoneFormSchema>;
|
|
8
|
+
/** Form values for email-based signup, inferred from the Zod schema. */
|
|
9
|
+
export type SignupEmailFormValues = z.infer<typeof signupEmailFormSchema>;
|
|
10
|
+
/** Form values for foreign signup (full name + email + phone), inferred from the Zod schema. */
|
|
11
|
+
export type SignupForeignFormValues = z.infer<typeof signupForeignFormSchema>;
|
|
12
|
+
/** Discriminated union of all signup form value shapes. */
|
|
13
|
+
export type SignupFormValues = SignupPhoneFormValues | SignupEmailFormValues | SignupForeignFormValues;
|
|
14
|
+
/** Payload when signup form is valid. */
|
|
15
|
+
export type SignupSubmitData = {
|
|
16
|
+
fullName: string;
|
|
17
|
+
phone?: string;
|
|
18
|
+
email?: string;
|
|
19
|
+
countryCode?: string;
|
|
20
|
+
};
|
|
21
|
+
export interface UseSignupFormOptions {
|
|
22
|
+
/** Mode: phone, email as second field, or foreign (name + email + phone) */
|
|
23
|
+
mode: SignupEntryMode;
|
|
24
|
+
/** For foreign mode: pre-fill phone when user already entered it. */
|
|
25
|
+
defaultPhone?: string | undefined;
|
|
26
|
+
/** Sync callback with valid data. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
|
|
27
|
+
onSubmit?: ((data: SignupSubmitData) => void) | undefined;
|
|
28
|
+
/** When provided, hook runs: validate → submitApi(data) → onSuccess(). Consumer passes redirect in onSuccess. */
|
|
29
|
+
submitApi?: ((data: SignupSubmitData) => Promise<void>) | undefined;
|
|
30
|
+
/** Called after submitApi succeeds (e.g. router.push('/otp') or next step). */
|
|
31
|
+
onSuccess?: (() => void) | undefined;
|
|
32
|
+
/** Called when submitApi rejects or throws. */
|
|
33
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Return value of the `useSignupForm` hook, providing form state and mode flags. */
|
|
36
|
+
export interface UseSignupFormReturn {
|
|
37
|
+
/** react-hook-form methods bound to the current signup mode's schema. */
|
|
38
|
+
methods: UseFormReturn<SignupFormValues>;
|
|
39
|
+
/** Submit handler to pass to the form's `onSubmit`. Validates and dispatches signup data. */
|
|
40
|
+
handleSubmit: (data: SignupFormValues) => void;
|
|
41
|
+
/** True when mode is 'phone', false when mode is 'email'. For 'foreign' same as (mode === 'phone') for layout. */
|
|
42
|
+
isPhone: boolean;
|
|
43
|
+
/** True when mode is 'foreign' (full name + email + phone). */
|
|
44
|
+
isForeign: boolean;
|
|
45
|
+
/** True when current form values pass validation (for disabling Continue – edge cases 9, 16, 19). */
|
|
46
|
+
isFormValid: (data: SignupFormValues) => boolean;
|
|
47
|
+
/** True while submitApi is in flight. */
|
|
48
|
+
isSubmitting: boolean;
|
|
49
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a phone + country code pair into a single E.164-style string.
|
|
3
|
+
*
|
|
4
|
+
* Rules (shared by login-entry submission and the SSO flow's identifier /
|
|
5
|
+
* signup-details handlers):
|
|
6
|
+
* - Trim the phone value.
|
|
7
|
+
* - Empty phone → `''`.
|
|
8
|
+
* - Phone already starting with `+` → return as-is (caller-supplied E.164).
|
|
9
|
+
* - Otherwise: strip non-digits from the country code; prefix `+{cc}{phone}`
|
|
10
|
+
* if a country code is present, else return the bare phone digits.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildPhoneRecipient(phone?: string, countryCode?: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ZodError } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Applies Zod validation errors to a React Hook Form setError function.
|
|
4
|
+
* Used by form submit handlers to display field-level errors from schema validation.
|
|
5
|
+
*
|
|
6
|
+
* @param error - The ZodError from schema.safeParse when validation fails
|
|
7
|
+
* @param setError - RHF's setError (e.g. methods.setError)
|
|
8
|
+
*/
|
|
9
|
+
export declare function setFormErrorsFromZod(error: ZodError, setError: (path: string, opts: {
|
|
10
|
+
message: string;
|
|
11
|
+
}) => void): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central export for all validation schemas and helpers.
|
|
3
|
+
* Import from here: import { signupSchemas, loginSchemas, otpFormSchema } from '../validations';
|
|
4
|
+
*/
|
|
5
|
+
export type { OtpVerificationMode } from './schemas';
|
|
6
|
+
export { capitalizeWords, emailSchema, fullNameSchema, getResendCooldownSeconds, loginEmailFormSchema, loginPhoneFormSchema, loginSchemas, OTP_LENGTH, otpFormSchema, phoneSchema, RESEND_COOLDOWN_EMAIL_SECONDS, RESEND_COOLDOWN_PHONE_SECONDS, signupEmailFormSchema, signupForeignFormSchema, signupPhoneFormSchema, signupSchemas, } from './schemas';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Zod schemas for auth forms (signup, login, OTP).
|
|
3
|
+
* Single source of truth for all validation rules per PRODUCT_PROTOCOLS.
|
|
4
|
+
* Schemas are consumed by hooks (not components) to enforce clean layer separation.
|
|
5
|
+
* Future SSO API validation (e.g. server-side field constraints) can extend these schemas.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
/** Capitalize first letter of each word (PRODUCT_PROTOCOLS #25 – Naming conventions). */
|
|
9
|
+
export declare function capitalizeWords(value: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Full name: required, min 3 chars, trim, capitalize each word (Protocol #1, #25; Edge case 9).
|
|
12
|
+
*/
|
|
13
|
+
export declare const fullNameSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
14
|
+
/**
|
|
15
|
+
* Phone: required; accepts both legacy "countryCode-number" and direct numeric input.
|
|
16
|
+
* Valid when the normalized phone digits length is between 7 and 15.
|
|
17
|
+
*/
|
|
18
|
+
export declare const phoneSchema: z.ZodString;
|
|
19
|
+
/** Optional country calling code, normalized to digits (e.g. `91`). */
|
|
20
|
+
export declare const countryCodeSchema: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
21
|
+
/**
|
|
22
|
+
* Email: required, valid format, trim and lowercase before save (Edge case 10).
|
|
23
|
+
*/
|
|
24
|
+
export declare const emailSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
25
|
+
export declare const signupPhoneFormSchema: z.ZodObject<{
|
|
26
|
+
fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
27
|
+
phone: z.ZodString;
|
|
28
|
+
countryCode: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export declare const signupEmailFormSchema: z.ZodObject<{
|
|
31
|
+
fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
32
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export declare const signupForeignFormSchema: z.ZodObject<{
|
|
35
|
+
fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
36
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
37
|
+
phone: z.ZodString;
|
|
38
|
+
countryCode: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
export declare const signupSchemas: {
|
|
41
|
+
readonly phone: z.ZodObject<{
|
|
42
|
+
fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
43
|
+
phone: z.ZodString;
|
|
44
|
+
countryCode: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
readonly email: z.ZodObject<{
|
|
47
|
+
fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
48
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
readonly foreign: z.ZodObject<{
|
|
51
|
+
fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
52
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
53
|
+
phone: z.ZodString;
|
|
54
|
+
countryCode: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Phone validation per PRODUCT_PROTOCOLS #2, #5 and edge cases 3–5.
|
|
59
|
+
*/
|
|
60
|
+
export declare const loginPhoneFormSchema: z.ZodObject<{
|
|
61
|
+
phone: z.ZodString;
|
|
62
|
+
countryCode: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
/**
|
|
65
|
+
* Email validation: trim and lowercase per edge case 10.
|
|
66
|
+
*/
|
|
67
|
+
export declare const loginEmailFormSchema: z.ZodObject<{
|
|
68
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
export declare const loginSchemas: {
|
|
71
|
+
readonly phone: z.ZodObject<{
|
|
72
|
+
phone: z.ZodString;
|
|
73
|
+
countryCode: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
readonly email: z.ZodObject<{
|
|
76
|
+
email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
};
|
|
79
|
+
export declare const OTP_LENGTH = 6;
|
|
80
|
+
/** Resend cooldown: 60s for phone OTP, 2 min for email OTP (per design). */
|
|
81
|
+
export declare const RESEND_COOLDOWN_PHONE_SECONDS = 60;
|
|
82
|
+
export declare const RESEND_COOLDOWN_EMAIL_SECONDS = 120;
|
|
83
|
+
export type OtpVerificationMode = 'phone' | 'email';
|
|
84
|
+
export declare function getResendCooldownSeconds(mode: OtpVerificationMode): number;
|
|
85
|
+
export declare const otpFormSchema: z.ZodObject<{
|
|
86
|
+
otp: z.ZodArray<z.ZodString>;
|
|
87
|
+
}, z.core.$strip>;
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doct-ui-auth-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "Composable React auth SDK – layouts, login/signup/OTP pages, SSO provider, and auth flow hooks for Docthub",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"files": [
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
10
13
|
"keywords": [
|
|
11
14
|
"react",
|
|
12
15
|
"auth",
|
|
@@ -24,7 +27,7 @@
|
|
|
24
27
|
},
|
|
25
28
|
"scripts": {
|
|
26
29
|
"dev": "vite",
|
|
27
|
-
"build": "vite build && tsc -p tsconfig.build.json",
|
|
30
|
+
"build": "vite build && tsc --build tsconfig.build.json --force && tsc-alias -p tsconfig.build.json",
|
|
28
31
|
"prepublishOnly": "npm run build",
|
|
29
32
|
"lint": "biome lint .",
|
|
30
33
|
"preview": "vite preview",
|
|
@@ -70,8 +73,6 @@
|
|
|
70
73
|
},
|
|
71
74
|
"devDependencies": {
|
|
72
75
|
"@biomejs/biome": "^2.3.14",
|
|
73
|
-
"react": "^19.2.0",
|
|
74
|
-
"react-dom": "^19.2.0",
|
|
75
76
|
"@chromatic-com/storybook": "^5.0.0",
|
|
76
77
|
"@eslint/js": "^9.39.1",
|
|
77
78
|
"@storybook/addon-a11y": "^10.2.6",
|
|
@@ -96,10 +97,13 @@
|
|
|
96
97
|
"lint-staged": "^16.2.7",
|
|
97
98
|
"playwright": "^1.58.1",
|
|
98
99
|
"postcss": "^8.5.6",
|
|
100
|
+
"react": "^19.2.0",
|
|
101
|
+
"react-dom": "^19.2.0",
|
|
99
102
|
"storybook": "^10.2.6",
|
|
100
103
|
"tailwind-merge": "^3.0.1",
|
|
101
104
|
"tailwindcss": "^3.4.16",
|
|
102
105
|
"tailwindcss-animate": "^1.0.7",
|
|
106
|
+
"tsc-alias": "^1.8.17",
|
|
103
107
|
"typescript": "~5.6.2",
|
|
104
108
|
"typescript-eslint": "^8.46.4",
|
|
105
109
|
"vite": "^7.2.4",
|