doct-ui-auth-kit 1.0.12 → 1.0.13

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.
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doct-ui-auth-kit",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
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",