doct-ui-auth-kit 1.0.2 → 1.0.4

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.
Files changed (51) hide show
  1. package/dist/adapters/http-auth-adapter.d.ts +2 -1
  2. package/dist/auth-methods/apple.d.ts +1 -1
  3. package/dist/auth-methods/index.d.ts +1 -0
  4. package/dist/components/form/rhf-doct-phone-input.d.ts +1 -1
  5. package/dist/components/form/rhf-input-field.d.ts +1 -1
  6. package/dist/components/form/rhf-otp-input-field.d.ts +1 -1
  7. package/dist/components/layout/image-slider.d.ts +2 -19
  8. package/dist/components/layout/main-layout.d.ts +2 -46
  9. package/dist/core/auth-api-adapter.d.ts +1 -33
  10. package/dist/core/auth-context.d.ts +4 -50
  11. package/dist/core/auth-provider.d.ts +2 -35
  12. package/dist/core/auth-types.d.ts +3 -68
  13. package/dist/core/device-detection.d.ts +2 -6
  14. package/dist/core/sso-session.d.ts +20 -6
  15. package/dist/core/use-auth-flow.d.ts +2 -75
  16. package/dist/hooks/index.d.ts +2 -0
  17. package/dist/hooks/use-login-entry-form.d.ts +4 -28
  18. package/dist/hooks/use-main-auth-page-handlers.d.ts +8 -0
  19. package/dist/hooks/use-otp-verification.d.ts +7 -31
  20. package/dist/hooks/use-repeat-login.d.ts +7 -0
  21. package/dist/hooks/use-signup-form.d.ts +4 -44
  22. package/dist/index.js +2981 -3435
  23. package/dist/pages/index.d.ts +5 -5
  24. package/dist/pages/login-entry.d.ts +40 -21
  25. package/dist/pages/main-login.d.ts +30 -14
  26. package/dist/pages/otp-verification.d.ts +43 -21
  27. package/dist/pages/repeat-login.d.ts +47 -18
  28. package/dist/pages/signup.d.ts +43 -23
  29. package/dist/pages.js +5 -5
  30. package/dist/signup-BpiNvZy4.js +1714 -0
  31. package/dist/types/auth-api-adapter.d.ts +43 -0
  32. package/dist/types/auth-provider.d.ts +37 -0
  33. package/dist/types/auth-types.d.ts +70 -0
  34. package/dist/types/device-detection.d.ts +7 -0
  35. package/dist/types/flow.d.ts +125 -0
  36. package/dist/types/forms.d.ts +2 -0
  37. package/dist/types/index.d.ts +13 -0
  38. package/dist/types/layout.d.ts +57 -0
  39. package/dist/types/login-form.d.ts +39 -0
  40. package/dist/types/main-login.d.ts +29 -0
  41. package/dist/types/otp-verification.d.ts +28 -0
  42. package/dist/types/pages.d.ts +133 -0
  43. package/dist/types/repeat-login.d.ts +28 -0
  44. package/dist/types/signup-form.d.ts +41 -0
  45. package/dist/types/sso-session.d.ts +33 -0
  46. package/dist/utils/index.d.ts +4 -0
  47. package/dist/utils/set-form-errors-from-zod.d.ts +11 -0
  48. package/dist/validations/index.d.ts +6 -0
  49. package/dist/validations/schemas.d.ts +76 -0
  50. package/package.json +105 -104
  51. package/dist/signup-x-Jm7XKn.js +0 -668
@@ -0,0 +1,43 @@
1
+ /**
2
+ * API adapter types for the SSO auth SDK.
3
+ * Consumers implement AuthApiAdapter to connect the SDK to their central auth service.
4
+ */
5
+ import type { AuthenticateWithProviderParams, CompleteProfileParams, SendOtpResponse, SSOSession, VerifyOtpResponse } from './auth-types';
6
+ /** Parameters for sending OTP to phone or email. */
7
+ export interface SendOtpParams {
8
+ type: 'phone' | 'email';
9
+ value: string;
10
+ }
11
+ /** Parameters for verifying OTP. */
12
+ export interface VerifyOtpParams {
13
+ type: 'phone' | 'email';
14
+ value: string;
15
+ otp: string;
16
+ }
17
+ /**
18
+ * Adapter implemented by the consumer to talk to the central auth service.
19
+ * All methods return promises; the SDK handles loading/error state.
20
+ */
21
+ export interface AuthApiAdapter {
22
+ /** Send OTP to the given phone or email. */
23
+ sendOtp(params: SendOtpParams): Promise<SendOtpResponse>;
24
+ /**
25
+ * Verify OTP. Returns session if existing user, or isNewUser flag for profile completion.
26
+ * May return conflict error when identifier is linked to another account.
27
+ */
28
+ verifyOtp(params: VerifyOtpParams): Promise<VerifyOtpResponse>;
29
+ /** Complete profile for new users; returns SSO session. */
30
+ completeProfile(params: CompleteProfileParams): Promise<SSOSession>;
31
+ /** Authenticate with a third-party provider (Google/Apple) credential. */
32
+ authenticateWithProvider(params: AuthenticateWithProviderParams): Promise<VerifyOtpResponse>;
33
+ /** Validate an existing SSO session token; called on SDK mount. Returns null if invalid/expired. */
34
+ validateSession(token: string): Promise<SSOSession | null>;
35
+ /**
36
+ * Optional: validate session using server-read cookie (no token from client).
37
+ * Required when using serverCookieTokenStorage. Client sends credentials;
38
+ * server reads cookie from the request and returns session or null.
39
+ */
40
+ validateSessionFromCookie?(): Promise<SSOSession | null>;
41
+ /** Optional: refresh an expired SSO session using refresh token. */
42
+ refreshSession?(refreshToken: string): Promise<SSOSession | null>;
43
+ }
@@ -0,0 +1,37 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { AuthApiAdapter } from './auth-api-adapter';
3
+ import type { AuthError, SSOSession } from './auth-types';
4
+ import type { TokenStorageStrategy } from './sso-session';
5
+ /** Consumer-provided config for SSOAuthProvider. */
6
+ export interface SSOAuthConfig {
7
+ /** Consumer-provided adapter to their central auth service. */
8
+ apiAdapter: AuthApiAdapter;
9
+ /** Auth method configs (Google client ID, Apple client ID, etc.). */
10
+ providers?: {
11
+ google?: {
12
+ clientId: string;
13
+ enableOneTap?: boolean;
14
+ };
15
+ apple?: {
16
+ clientId: string;
17
+ redirectUri: string;
18
+ };
19
+ };
20
+ /** Called when SSO session is established (any method). */
21
+ onAuthSuccess: (session: SSOSession) => void;
22
+ /** Called on auth errors. */
23
+ onAuthError?: (error: AuthError) => void;
24
+ /** Optional: called when user signs out. */
25
+ onSignOut?: () => void;
26
+ /** SSO token persistence strategy. Defaults to localStorage. */
27
+ tokenStorage?: TokenStorageStrategy;
28
+ /** Branding customization (logo, slider images). */
29
+ branding?: {
30
+ logo?: ReactNode;
31
+ sliderImages?: string[];
32
+ };
33
+ }
34
+ export interface SSOAuthProviderProps {
35
+ config: SSOAuthConfig;
36
+ children: ReactNode;
37
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * SSO auth domain types: session, flow steps, adapter contracts, and error codes.
3
+ * Used by the flow engine, provider, and adapter implementations.
4
+ */
5
+ /** Auth methods available in the SSO system. */
6
+ export type AuthMethod = 'phone' | 'email' | 'google' | 'apple';
7
+ /** User payload in the SSO session. */
8
+ export interface SSOUser {
9
+ id: string;
10
+ name: string;
11
+ email?: string;
12
+ phone?: string;
13
+ avatar?: string;
14
+ isNewUser: boolean;
15
+ }
16
+ /** The SSO session — same structure regardless of auth method used. */
17
+ export interface SSOSession {
18
+ accessToken: string;
19
+ refreshToken?: string;
20
+ expiresAt: number;
21
+ user: SSOUser;
22
+ authMethod: AuthMethod;
23
+ }
24
+ /** User type for layout and OTP routing: Indian (+91) vs Foreign (non +91). */
25
+ export type UserType = 'INDIAN' | 'FOREIGN';
26
+ /** Flow states for the state machine. */
27
+ export type AuthStep = 'CHECKING_SESSION' | 'REPEAT_LOGIN' | 'METHOD_SELECT' | 'PHONE_ENTRY' | 'EMAIL_ENTRY' | 'OTP_VERIFICATION' | 'SIGNUP_DETAILS' | 'PROVIDER_PENDING' | 'AUTHENTICATED';
28
+ /** Error codes from the central auth service. */
29
+ export type AuthErrorCode = 'IDENTIFIER_CONFLICT' | 'OTP_EXPIRED' | 'OTP_INVALID' | 'OTP_RATE_LIMIT' | 'SESSION_EXPIRED' | 'PROVIDER_AUTH_FAILED' | 'NETWORK_ERROR' | 'UNKNOWN';
30
+ /** Auth error with code and optional message / linked identifier. */
31
+ export interface AuthError {
32
+ code: AuthErrorCode;
33
+ message?: string;
34
+ /** Masked linked identifier when conflict (e.g. "+91 98XXXX0X0X"). */
35
+ linkedIdentifier?: string;
36
+ }
37
+ /** Response from sendOtp. */
38
+ export interface SendOtpResponse {
39
+ success: boolean;
40
+ /** Masked value for display (e.g. "+91 9825910X0X" or "j***@gmail.com"). */
41
+ maskedValue?: string;
42
+ error?: AuthError;
43
+ }
44
+ /** Result of verifyOtp or authenticateWithProvider: existing user gets session, new user gets profile step. */
45
+ export interface VerifyOtpResponse {
46
+ /** Present when user exists and is authenticated. */
47
+ session?: SSOSession;
48
+ /** True when user is new and must complete profile. */
49
+ isNewUser: boolean;
50
+ /** When isNewUser and conflict (e.g. email already linked), masked linked identifier. */
51
+ conflict?: AuthError;
52
+ }
53
+ /** Input for completeProfile (new users). */
54
+ export interface CompleteProfileParams {
55
+ fullName: string;
56
+ email?: string;
57
+ phone?: string;
58
+ }
59
+ /** Input for authenticateWithProvider (Google/Apple credential). */
60
+ export interface AuthenticateWithProviderParams {
61
+ provider: 'google' | 'apple';
62
+ /** Id token or equivalent from the provider. */
63
+ credential: string;
64
+ }
65
+ /** Repeat-login device history (method + masked identifier). */
66
+ export interface RepeatLoginInfo {
67
+ method: AuthMethod;
68
+ maskedIdentifier: string;
69
+ timestamp: number;
70
+ }
@@ -0,0 +1,7 @@
1
+ import type { AuthMethod } from './auth-types';
2
+ /** Stored repeat-login info (method + masked identifier). */
3
+ export interface StoredRepeatLogin {
4
+ method: AuthMethod;
5
+ maskedIdentifier: string;
6
+ timestamp: number;
7
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Auth flow state machine types: state, actions, and context.
3
+ */
4
+ import type { AuthStep, SSOSession, UserType } from './auth-types';
5
+ /** Identifier type for OTP / profile steps. */
6
+ export type IdentifierType = 'phone' | 'email';
7
+ /** Full state for the auth flow. */
8
+ export interface AuthFlowState {
9
+ step: AuthStep;
10
+ /** Previous step for goBack. */
11
+ lastStep: AuthStep;
12
+ /** Indian (+91) vs Foreign (non +91); drives layout and OTP routing. */
13
+ userType: UserType;
14
+ /** Current identifier value (phone or email) when in OTP or signup. */
15
+ identifierValue: string;
16
+ /** Type of identifier (phone vs email). */
17
+ identifierType: IdentifierType;
18
+ /** Masked value for display (e.g. "+91 9825910X0X"). */
19
+ maskedRecipient: string;
20
+ /** For SIGNUP_DETAILS (Indian): which field to collect (phone or email). */
21
+ signupCollectField: IdentifierType;
22
+ /** For REPEAT_LOGIN: last used method label. */
23
+ lastMethod: string;
24
+ /** Set when step is AUTHENTICATED. */
25
+ session: SSOSession | null;
26
+ /** Foreign flow: phone value when user entered phone before signup details. */
27
+ pendingPhone: string;
28
+ /** Foreign flow: signup form data for completeProfile after OTP verify. */
29
+ pendingFullName: string;
30
+ pendingEmail: string;
31
+ }
32
+ /** Pure reducer actions. */
33
+ export type AuthFlowAction = {
34
+ type: 'SET_SESSION';
35
+ session: SSOSession;
36
+ } | {
37
+ type: 'SET_STEP_REPEAT_LOGIN';
38
+ lastMethod: string;
39
+ maskedIdentifier: string;
40
+ } | {
41
+ type: 'SET_STEP_METHOD_SELECT';
42
+ } | {
43
+ type: 'SET_STEP_PHONE_ENTRY';
44
+ } | {
45
+ type: 'SET_STEP_EMAIL_ENTRY';
46
+ } | {
47
+ type: 'SET_STEP_OTP_VERIFICATION';
48
+ userType: UserType;
49
+ identifierType: IdentifierType;
50
+ value: string;
51
+ maskedValue: string;
52
+ /** Foreign flow: for completeProfile after OTP. */
53
+ pendingFullName?: string;
54
+ pendingEmail?: string;
55
+ pendingPhone?: string;
56
+ } | {
57
+ type: 'SET_STEP_SIGNUP_DETAILS';
58
+ userType: UserType;
59
+ /** Indian: which field to collect (phone or email). Foreign: ignored. */
60
+ signupCollectField: IdentifierType;
61
+ /** Foreign only: phone value when user entered phone before signup. */
62
+ pendingPhone?: string;
63
+ /** When coming from identifier entry (foreign): preserve for later OTP. */
64
+ identifierType?: IdentifierType;
65
+ identifierValue?: string;
66
+ maskedRecipient?: string;
67
+ } | {
68
+ type: 'SET_STEP_PROVIDER_PENDING';
69
+ } | {
70
+ type: 'SET_STEP_AUTHENTICATED';
71
+ session: SSOSession;
72
+ } | {
73
+ type: 'GO_BACK';
74
+ } | {
75
+ type: 'RESET';
76
+ } | {
77
+ type: 'SIGN_OUT';
78
+ };
79
+ /** Provider config slice exposed to flow for Google/Apple wiring. */
80
+ export interface AuthFlowProviderConfig {
81
+ google?: {
82
+ clientId: string;
83
+ enableOneTap?: boolean;
84
+ };
85
+ apple?: {
86
+ clientId: string;
87
+ redirectUri: string;
88
+ };
89
+ }
90
+ /** Async actions that perform I/O and dispatch to the flow reducer. */
91
+ export interface AuthFlowActions {
92
+ selectMethod: (method: 'phone' | 'email' | 'google' | 'apple') => void;
93
+ /** From REPEAT_LOGIN: continue with last used method. */
94
+ continueWithLastMethod: () => void;
95
+ submitIdentifier: (data: {
96
+ phone?: string;
97
+ email?: string;
98
+ }) => void;
99
+ /** SIGNUP_DETAILS step: submit name + phone/email, then OTP (foreign) or complete (Indian). */
100
+ submitSignupDetails: (data: {
101
+ fullName: string;
102
+ phone?: string;
103
+ email?: string;
104
+ }) => void;
105
+ verifyOtp: (otp: string) => void;
106
+ resendOtp: () => void;
107
+ providerCallback: (params: {
108
+ provider: 'google' | 'apple';
109
+ credential: string;
110
+ }) => void;
111
+ goBack: () => void;
112
+ reset: () => void;
113
+ signOut: () => void;
114
+ }
115
+ /** Auth flow context value provided by SSOAuthProvider. */
116
+ export interface AuthFlowContextValue {
117
+ state: AuthFlowState;
118
+ actions: AuthFlowActions;
119
+ /** Session when step is AUTHENTICATED. */
120
+ session: SSOSession | null;
121
+ /** True while step is CHECKING_SESSION. */
122
+ isLoading: boolean;
123
+ /** Provider config for Google/Apple (One Tap, Sign-In button). */
124
+ providerConfig: AuthFlowProviderConfig | undefined;
125
+ }
@@ -10,6 +10,8 @@ export interface BaseFormFieldProps {
10
10
  className?: string;
11
11
  error?: string;
12
12
  helperText?: string;
13
+ /** Focus this field when form/screen opens (PRODUCT_PROTOCOLS #26). */
14
+ autoFocus?: boolean;
13
15
  }
14
16
  /** Props for the text/email/number input field component. */
15
17
  export interface RHFInputFieldProps extends BaseFormFieldProps {
@@ -2,6 +2,19 @@
2
2
  * Central export file for all types and interfaces.
3
3
  * Import types from here: import type { RHFInputFieldProps } from '@/types';
4
4
  */
5
+ export * from './auth-api-adapter';
5
6
  export * from './auth-layout-types';
7
+ export * from './auth-provider';
8
+ export * from './auth-types';
9
+ export * from './device-detection';
10
+ export * from './flow';
6
11
  export * from './forms';
12
+ export * from './layout';
7
13
  export * from './layout-presets';
14
+ export * from './login-form';
15
+ export * from './main-login';
16
+ export * from './otp-verification';
17
+ export * from './pages';
18
+ export * from './repeat-login';
19
+ export * from './signup-form';
20
+ export * from './sso-session';
@@ -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,39 @@
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
+ export type PhoneFormValues = z.infer<typeof loginPhoneFormSchema>;
7
+ export type EmailFormValues = z.infer<typeof loginEmailFormSchema>;
8
+ export type LoginEntryFormValues = PhoneFormValues | EmailFormValues;
9
+ /** Payload when login entry form is valid (phone or email). */
10
+ export type LoginEntrySubmitData = {
11
+ phone?: string;
12
+ email?: string;
13
+ };
14
+ export interface UseLoginEntryFormOptions {
15
+ mode: LoginEntryMode;
16
+ /**
17
+ * Sync callback with valid form data. Used when parent owns API (e.g. AuthFlow passes actions.submitIdentifier).
18
+ * Ignored when submitApi is provided.
19
+ */
20
+ onSubmit?: ((data: LoginEntrySubmitData) => void) | undefined;
21
+ /**
22
+ * When provided, hook runs business logic: validate → call submitApi(data) → onSuccess().
23
+ * Use from consumer (e.g. Next.js): submitApi = sendOtp, onSuccess = () => router.push('/otp').
24
+ */
25
+ submitApi?: (data: LoginEntrySubmitData) => Promise<void>;
26
+ /** Called after submitApi resolves successfully (e.g. redirect to OTP page). */
27
+ onSuccess?: () => void;
28
+ /** Called when submitApi rejects or throws. */
29
+ onError?: (error: unknown) => void;
30
+ }
31
+ export interface UseLoginEntryFormReturn {
32
+ methods: UseFormReturn<LoginEntryFormValues>;
33
+ handleSubmit: (data: LoginEntryFormValues) => void;
34
+ isPhone: boolean;
35
+ /** True when current form values pass validation (for disabling Continue until valid – edge cases 3, 4). */
36
+ isFormValid: (data: LoginEntryFormValues) => boolean;
37
+ /** True while submitApi is in flight. Use to disable Continue button and show loading. */
38
+ isSubmitting: boolean;
39
+ }
@@ -0,0 +1,29 @@
1
+ /** Handlers exposed by the main auth page (method select). */
2
+ export interface MainAuthPageHandlers {
3
+ onContinueWithMobile: () => void;
4
+ onContinueWithEmail: () => void;
5
+ onContinueWithGoogle: () => void;
6
+ onContinueWithApple: () => void;
7
+ }
8
+ /** Config for lib-handled Google sign-in. When set, the lib runs the OAuth flow and calls onCredential. */
9
+ export interface MainLoginGoogleProviderConfig {
10
+ clientId: string;
11
+ /** Called with ID token (One Tap) or auth code (button popup). Send to your backend to verify. */
12
+ onCredential: (credential: string) => void;
13
+ enableOneTap?: boolean;
14
+ }
15
+ /** Config for lib-handled Apple sign-in (stub). When set, the lib will run the flow and call onCredential when implemented. */
16
+ export interface MainLoginAppleProviderConfig {
17
+ clientId: string;
18
+ redirectUri: string;
19
+ onCredential: (credential: string) => void;
20
+ }
21
+ /** Optional provider config so the lib handles Google/Apple API calls. */
22
+ export interface MainLoginPageProvidersConfig {
23
+ google?: MainLoginGoogleProviderConfig;
24
+ apple?: MainLoginAppleProviderConfig;
25
+ }
26
+ /** Options for useMainAuthPageHandlers: optional callback overrides + optional provider config for lib-handled OAuth. */
27
+ export type UseMainAuthPageHandlersOptions = Partial<MainAuthPageHandlers> & {
28
+ providers?: MainLoginPageProvidersConfig;
29
+ };
@@ -0,0 +1,28 @@
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
+ export type OtpFormValues = z.infer<typeof otpFormSchema>;
6
+ export interface UseOtpVerificationOptions {
7
+ /** OTP mode: phone (60s cooldown) or email (2 min cooldown). */
8
+ mode: OtpVerificationMode;
9
+ /** Sync callback with OTP string. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
10
+ onSubmit?: ((otp: string) => void) | undefined;
11
+ onResendCode?: (() => void) | undefined;
12
+ /** When provided, hook runs: validate → submitApi(otp) → onSuccess(). Consumer passes redirect in onSuccess. */
13
+ submitApi?: (otp: string) => Promise<void>;
14
+ /** Called after submitApi resolves (e.g. router.push('/dashboard')). */
15
+ onSuccess?: () => void;
16
+ /** Called when submitApi rejects or throws. */
17
+ onError?: (error: unknown) => void;
18
+ }
19
+ export interface UseOtpVerificationReturn {
20
+ methods: UseFormReturn<OtpFormValues>;
21
+ handleSubmit: (data: OtpFormValues) => void;
22
+ handleResend: () => void;
23
+ resendSecondsLeft: number;
24
+ canResend: boolean;
25
+ timerText: string;
26
+ /** True while submitApi is in flight. */
27
+ isSubmitting: boolean;
28
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Props and public types for auth page components.
3
+ */
4
+ import type { UserType } from './auth-types';
5
+ import type { IdentifierType } from './flow';
6
+ import type { LoginEntryMode } from './login-form';
7
+ import type { UseMainAuthPageHandlersOptions } from './main-login';
8
+ import type { 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
+ }) => void;
29
+ /**
30
+ * Async API call (e.g. send OTP). When provided, hook runs: validate → submitApi(data) → onSuccess().
31
+ * Consumer (e.g. Next.js) can pass redirect in onSuccess.
32
+ */
33
+ submitApi?: (data: {
34
+ phone?: string;
35
+ email?: string;
36
+ }) => Promise<void>;
37
+ /** Called after submitApi succeeds (e.g. router.push('/otp')). */
38
+ onSuccess?: () => void;
39
+ /** Called when submitApi fails. */
40
+ onError?: (error: unknown) => void;
41
+ }
42
+ /** Props for the full LoginEntryPage (adds optional layout overrides for story/viewport). */
43
+ export interface LoginEntryPageProps extends LoginEntryProps {
44
+ /** Layout type. Default: 'withSlider' for desktop, use 'standalone' for mobile. */
45
+ layoutType?: 'withSlider' | 'standalone';
46
+ /** Layout variant. Default derived from layoutType if not set. */
47
+ variant?: 'desktop' | 'mobile';
48
+ }
49
+ /** Props for Signup (inner form without layout). */
50
+ export interface SignupPageProps {
51
+ /** Indian: which field to collect. Foreign: use 'foreign' mode (name + email + phone). */
52
+ userType: UserType;
53
+ /** How user started (phone or email). */
54
+ loginMethod: IdentifierType;
55
+ /** Indian only: which field to collect (phone or email). */
56
+ signupCollectField: IdentifierType;
57
+ /** Foreign only: phone when user entered phone before signup details. */
58
+ pendingPhone?: string;
59
+ /** Sync callback with valid data. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
60
+ onSubmit?: (data: {
61
+ fullName: string;
62
+ phone?: string;
63
+ email?: string;
64
+ }) => void;
65
+ /** Async API (e.g. complete profile). When provided, hook runs: validate → submitApi(data) → onSuccess(). */
66
+ submitApi?: (data: {
67
+ fullName: string;
68
+ phone?: string;
69
+ email?: string;
70
+ }) => Promise<void>;
71
+ /** Called after submitApi succeeds (e.g. router.push('/otp') or next step). */
72
+ onSuccess?: () => void;
73
+ /** Called when submitApi fails. */
74
+ onError?: (error: unknown) => void;
75
+ }
76
+ /** Props for the full SignupPage (adds optional layout overrides). */
77
+ export interface SignupPageFullProps extends SignupPageProps {
78
+ layoutType?: 'withSlider' | 'standalone';
79
+ variant?: 'desktop' | 'mobile';
80
+ }
81
+ /** Props for OtpVerification (inner form without layout). */
82
+ export interface OtpVerificationProps {
83
+ /** Mode: mobile (phone) or email OTP */
84
+ mode: OtpVerificationMode;
85
+ /** Title override. Default: "6 digit OTP has been sent to your Mobile" | "..." Email */
86
+ title?: string;
87
+ /** Masked phone (e.g. "+91 9825910X0X") or email (e.g. "j***@gmail.com") */
88
+ recipientDisplay: string;
89
+ /** When true, show instruction line ("Kindly check your Email Inbox."). Used for foreign user flow. */
90
+ isForeignUser?: boolean;
91
+ /** Handler when back is clicked */
92
+ onBack?: () => void;
93
+ /** Sync callback with OTP. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
94
+ onSubmit?: (otp: string) => void;
95
+ /** Handler when user requests resend code */
96
+ onResendCode?: () => void;
97
+ /** Async API (e.g. verify OTP). When provided, hook runs: validate → submitApi(otp) → onSuccess(). */
98
+ submitApi?: (otp: string) => Promise<void>;
99
+ /** Called after submitApi succeeds (e.g. router.push('/dashboard')). */
100
+ onSuccess?: () => void;
101
+ /** Called when submitApi fails. */
102
+ onError?: (error: unknown) => void;
103
+ }
104
+ /** Props for the full OtpVerificationPage (adds optional layout overrides). */
105
+ export interface OtpVerificationPageProps extends OtpVerificationProps {
106
+ layoutType?: 'withSlider' | 'standalone';
107
+ variant?: 'desktop' | 'mobile';
108
+ }
109
+ /** Props for RepeatLogin (inner component without layout). */
110
+ export interface RepeatLoginProps {
111
+ /**
112
+ * Last used authentication method shown in the primary button label.
113
+ * Example: "Mobile", "Email".
114
+ *
115
+ * @default "Mobile"
116
+ */
117
+ lastUsedMethod?: string;
118
+ /** Sync handler for primary action. Use when caller owns API (e.g. AuthFlow). Ignored when continueApi is provided. */
119
+ onContinueWithLastMethod?: () => void;
120
+ /** Handler for the secondary action (choose another method). */
121
+ onUseAnotherMethod?: () => void;
122
+ /** Async API for continue (e.g. validate session). When provided, hook runs: continueApi() → onSuccess(). */
123
+ continueApi?: () => Promise<void>;
124
+ /** Called after continueApi succeeds (e.g. router.push('/dashboard')). */
125
+ onSuccess?: () => void;
126
+ /** Called when continueApi fails. */
127
+ onError?: (error: unknown) => void;
128
+ }
129
+ /** Props for the full RepeatLoginPage (adds optional layout overrides). */
130
+ export interface RepeatLoginPageProps extends RepeatLoginProps {
131
+ layoutType?: 'withSlider' | 'standalone';
132
+ variant?: 'desktop' | 'mobile';
133
+ }
@@ -0,0 +1,28 @@
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;
10
+ /** Sync handler for primary action. Use when caller owns API (e.g. AuthFlow). Ignored when continueApi is provided. */
11
+ onContinueWithLastMethod?: () => void;
12
+ /** Handler for the secondary action (choose another method). */
13
+ onUseAnotherMethod?: () => void;
14
+ /** Async API for continue (e.g. validate session). When provided, hook runs: continueApi() → onSuccess(). */
15
+ continueApi?: () => Promise<void>;
16
+ /** Called after continueApi succeeds (e.g. router.push('/dashboard')). */
17
+ onSuccess?: () => void;
18
+ /** Called when continueApi fails. */
19
+ onError?: (error: unknown) => void;
20
+ }
21
+ export interface UseRepeatLoginReturn {
22
+ /** Call this when the user clicks "Continue with {lastUsedMethod}". */
23
+ handleContinue: () => void;
24
+ /** True while continueApi is in flight. */
25
+ isSubmitting: boolean;
26
+ /** Resolved lastUsedMethod for display (default "Mobile"). */
27
+ lastUsedMethod: string;
28
+ }