doct-ui-auth-kit 1.0.6 → 1.0.8
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 +1 -5
- package/dist/auth/index.d.ts +2 -2
- package/dist/components/form/rhf-doct-phone-input.d.ts +2 -1
- package/dist/components/form/rhf-input-field.d.ts +2 -1
- package/dist/components/form/rhf-otp-input-field.d.ts +2 -1
- package/dist/components/layout/auth-layout-preset.d.ts +7 -2
- package/dist/components/layout/auth-layout-public.d.ts +8 -12
- package/dist/components/layout/auth-layout-wrapper.d.ts +39 -3
- package/dist/components/layout/auth-layout.d.ts +1 -1
- package/dist/components/layout/image-slider.d.ts +2 -2
- package/dist/components/layout/index.d.ts +1 -1
- package/dist/components/layout/main-layout.d.ts +2 -2
- package/dist/constants/layout-presets.d.ts +1 -5
- package/dist/core/auth-api-adapter.d.ts +1 -1
- package/dist/core/auth-context.d.ts +5 -5
- package/dist/core/auth-flow.d.ts +2 -2
- package/dist/core/auth-provider.d.ts +5 -3
- package/dist/core/auth-types.d.ts +1 -1
- package/dist/core/device-detection.d.ts +2 -6
- package/dist/core/sso-session.d.ts +2 -6
- package/dist/core/use-auth-flow.d.ts +2 -6
- package/dist/doct-ui-auth-kit.css +1 -1
- package/dist/hooks/use-login-entry-form.d.ts +8 -4
- package/dist/hooks/use-main-auth-page-handlers.d.ts +6 -5
- package/dist/hooks/use-otp-verification.d.ts +7 -4
- package/dist/hooks/use-repeat-login.d.ts +6 -4
- package/dist/hooks/use-signup-form.d.ts +8 -3
- package/dist/index.d.ts +11 -36
- package/dist/index.js +28 -27
- package/dist/pages/index.d.ts +4 -1
- 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-DBRzdhNj.js +1546 -0
- package/dist/types/{auth-api-adapter.d.ts → auth/auth-api-adapter.d.ts} +1 -5
- package/dist/types/{auth-provider.d.ts → auth/auth-provider.d.ts} +7 -4
- package/dist/types/auth/device-detection.d.ts +10 -0
- package/dist/types/{flow.d.ts → auth/flow.d.ts} +1 -4
- package/dist/types/auth/index.d.ts +9 -0
- package/dist/types/{auth-layout-types.d.ts → components/auth-layout-types.d.ts} +1 -1
- package/dist/types/components/forms.d.ts +68 -0
- package/dist/types/components/index.d.ts +7 -0
- package/dist/types/{layout-presets.d.ts → components/layout-presets.d.ts} +1 -6
- package/dist/types/{layout.d.ts → components/layout.d.ts} +1 -1
- package/dist/types/index.d.ts +4 -17
- package/dist/types/pages/index.d.ts +9 -0
- package/dist/types/{login-form.d.ts → pages/login-form.d.ts} +13 -6
- package/dist/types/{main-login.d.ts → pages/main-login.d.ts} +11 -0
- package/dist/types/{otp-verification.d.ts → pages/otp-verification.d.ts} +16 -6
- package/dist/types/{pages.d.ts → pages/pages.d.ts} +32 -35
- package/dist/types/{repeat-login.d.ts → pages/repeat-login.d.ts} +7 -6
- package/dist/types/{signup-form.d.ts → pages/signup-form.d.ts} +14 -7
- package/dist/utils/set-form-errors-from-zod.d.ts +1 -1
- package/dist/validations/schemas.d.ts +0 -4
- package/package.json +2 -2
- package/dist/pages/login-entry.d.ts +0 -42
- package/dist/pages/main-login.d.ts +0 -32
- package/dist/pages/otp-verification.d.ts +0 -45
- package/dist/pages/repeat-login.d.ts +0 -49
- package/dist/pages/signup.d.ts +0 -4
- package/dist/signup-DeeuWsoF.js +0 -1718
- package/dist/types/device-detection.d.ts +0 -7
- package/dist/types/forms.d.ts +0 -42
- /package/dist/{stories/components → components/common}/default-footer.d.ts +0 -0
- /package/dist/{stories/components → components/common}/enterprise-header.d.ts +0 -0
- /package/dist/{stories/components → components/common}/index.d.ts +0 -0
- /package/dist/types/{auth-types.d.ts → auth/auth-types.d.ts} +0 -0
- /package/dist/types/{sso-session.d.ts → auth/sso-session.d.ts} +0 -0
|
@@ -1,8 +1,4 @@
|
|
|
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';
|
|
1
|
+
import { AuthenticateWithProviderParams, CompleteProfileParams, SendOtpResponse, SSOSession, VerifyOtpResponse } from './auth-types';
|
|
6
2
|
/** Parameters for sending OTP to phone or email. */
|
|
7
3
|
export interface SendOtpParams {
|
|
8
4
|
type: 'phone' | 'email';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AuthApiAdapter } from './auth-api-adapter';
|
|
3
|
+
import { AuthError, SSOSession } from './auth-types';
|
|
4
|
+
import { TokenStorageStrategy } from './sso-session';
|
|
5
5
|
/** Consumer-provided config for SSOAuthProvider. */
|
|
6
6
|
export interface SSOAuthConfig {
|
|
7
7
|
/** Consumer-provided adapter to their central auth service. */
|
|
@@ -31,7 +31,10 @@ export interface SSOAuthConfig {
|
|
|
31
31
|
sliderImages?: string[];
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
/** Props for the SSOAuthProvider context wrapper that supplies auth state to the component tree. */
|
|
34
35
|
export interface SSOAuthProviderProps {
|
|
36
|
+
/** Auth configuration including API adapter, provider settings, and callbacks. */
|
|
35
37
|
config: SSOAuthConfig;
|
|
38
|
+
/** Child components that will have access to the SSO auth context. */
|
|
36
39
|
children: ReactNode;
|
|
37
40
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthMethod } from './auth-types';
|
|
2
|
+
/** Stored repeat-login info (method + masked identifier). */
|
|
3
|
+
export interface StoredRepeatLogin {
|
|
4
|
+
/** The authentication method used in the previous login (e.g. `'phone'`, `'email'`, `'google'`). */
|
|
5
|
+
method: AuthMethod;
|
|
6
|
+
/** Partially masked identifier shown to the user (e.g. `"****1234"` or `"j***@example.com"`). */
|
|
7
|
+
maskedIdentifier: string;
|
|
8
|
+
/** Unix epoch (ms) when this login record was stored. Used for expiry checks. */
|
|
9
|
+
timestamp: number;
|
|
10
|
+
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Auth flow state machine types: state, actions, and context.
|
|
3
|
-
*/
|
|
4
|
-
import type { AuthStep, SSOSession, UserType } from './auth-types';
|
|
1
|
+
import { AuthStep, SSOSession, UserType } from './auth-types';
|
|
5
2
|
/** Identifier type for OTP / profile steps. */
|
|
6
3
|
export type IdentifierType = 'phone' | 'email';
|
|
7
4
|
/** Full state for the auth flow. */
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth domain types: session, adapter, provider, flow state, errors, device detection.
|
|
3
|
+
*/
|
|
4
|
+
export * from './auth-types';
|
|
5
|
+
export * from './auth-api-adapter';
|
|
6
|
+
export * from './auth-provider';
|
|
7
|
+
export * from './sso-session';
|
|
8
|
+
export * from './device-detection';
|
|
9
|
+
export * from './flow';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { KeyboardEvent } from 'react';
|
|
2
|
+
import { Control, FieldValues } from 'react-hook-form';
|
|
3
|
+
/** Base props shared by RHF form field components. */
|
|
4
|
+
export interface BaseFormFieldProps {
|
|
5
|
+
/** Field name used by react-hook-form for registration and validation. */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Visible label rendered above or beside the input. */
|
|
8
|
+
label?: string;
|
|
9
|
+
/** Placeholder text shown when the input is empty. */
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
/** Whether the field is required for form submission. */
|
|
12
|
+
required?: boolean;
|
|
13
|
+
/** Whether the field is disabled (non-interactive). */
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** Additional CSS class name(s) applied to the field wrapper. */
|
|
16
|
+
className?: string;
|
|
17
|
+
/** Validation error message to display below the input. */
|
|
18
|
+
error?: string;
|
|
19
|
+
/** Supplementary helper text shown below the input when there is no error. */
|
|
20
|
+
helperText?: string;
|
|
21
|
+
/** Focus this field when form/screen opens (PRODUCT_PROTOCOLS #26). */
|
|
22
|
+
autoFocus?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Props for the text/email/number input field component. */
|
|
25
|
+
export interface RHFInputFieldProps extends BaseFormFieldProps {
|
|
26
|
+
/** HTML input type. Allowed: `'text'`, `'email'`, `'password'`, `'number'`, `'tel'`, `'url'`, `'search'`. */
|
|
27
|
+
type?: 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'search';
|
|
28
|
+
/** HTML `autocomplete` attribute value (e.g. `'email'`, `'tel'`). */
|
|
29
|
+
autoComplete?: string;
|
|
30
|
+
/** Maximum character length enforced on the input. */
|
|
31
|
+
maxLength?: number;
|
|
32
|
+
/** Minimum character length enforced on the input. */
|
|
33
|
+
minLength?: number;
|
|
34
|
+
/** Regex pattern string for native HTML validation. */
|
|
35
|
+
pattern?: string;
|
|
36
|
+
/** react-hook-form `Control` instance. When omitted, the field uses the nearest `FormProvider`. */
|
|
37
|
+
control?: Control<FieldValues>;
|
|
38
|
+
/** Called when a key is pressed while the input is focused. */
|
|
39
|
+
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
|
40
|
+
/** When true, restricts input to numeric characters only. */
|
|
41
|
+
numericOnly?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** Props for RHF wrapper around DoctPhoneInput (docthub-core-components). */
|
|
44
|
+
export interface RHFDoctPhoneInputFieldProps extends BaseFormFieldProps {
|
|
45
|
+
/** ISO 3166-1 alpha-2 country code pre-selected in the phone input (e.g. `'IN'`, `'US'`). */
|
|
46
|
+
defaultCountry?: string;
|
|
47
|
+
/** Display variant: `'default'` shows full country selector, `'flag'` shows flag icon only. */
|
|
48
|
+
variant?: 'default' | 'flag';
|
|
49
|
+
/** react-hook-form `Control` instance. When omitted, the field uses the nearest `FormProvider`. */
|
|
50
|
+
control?: Control<FieldValues>;
|
|
51
|
+
}
|
|
52
|
+
/** Props for the OTP input field component. */
|
|
53
|
+
export interface RHFOtpInputFieldProps extends BaseFormFieldProps {
|
|
54
|
+
/** Number of OTP digit boxes to render. @default 6 */
|
|
55
|
+
length?: number;
|
|
56
|
+
/** Input type for each OTP box: `'text'`, `'number'`, or `'password'` (masked). */
|
|
57
|
+
type?: 'text' | 'number' | 'password';
|
|
58
|
+
/** Focus the first OTP box on mount. */
|
|
59
|
+
autoFocus?: boolean;
|
|
60
|
+
/** Automatically trigger submission when all boxes are filled. */
|
|
61
|
+
autoSubmit?: boolean;
|
|
62
|
+
/** Called with the complete OTP string once all boxes are filled. */
|
|
63
|
+
onComplete?: (otp: string) => void;
|
|
64
|
+
/** CSS class name(s) applied to each individual OTP input box. */
|
|
65
|
+
inputClassName?: string;
|
|
66
|
+
/** react-hook-form `Control` instance. When omitted, the field uses the nearest `FormProvider`. */
|
|
67
|
+
control?: Control<FieldValues>;
|
|
68
|
+
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Layout preset types for the Auth SDK.
|
|
3
|
-
* Presets control structure only: width, alignment, slider vs standalone.
|
|
4
|
-
* They do NOT control auth methods, MFA, or flow behavior.
|
|
5
|
-
*/
|
|
6
|
-
import type { AuthLayoutAlign, AuthLayoutMaxWidth, AuthLayoutVariant } from './auth-layout-types';
|
|
1
|
+
import { AuthLayoutAlign, AuthLayoutMaxWidth, AuthLayoutVariant } from './auth-layout-types';
|
|
7
2
|
/** Layout type: two-panel with slider vs single centered column. */
|
|
8
3
|
export type LayoutType = 'withSlider' | 'standalone';
|
|
9
4
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Central export
|
|
3
|
-
*
|
|
2
|
+
* Central export for all types and interfaces.
|
|
3
|
+
* Organized by domain: auth (SSO), components (props), pages (page-specific).
|
|
4
4
|
*/
|
|
5
|
-
export * from './auth
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './auth-provider';
|
|
8
|
-
export * from './auth-types';
|
|
9
|
-
export * from './device-detection';
|
|
10
|
-
export * from './flow';
|
|
11
|
-
export * from './forms';
|
|
12
|
-
export * from './layout';
|
|
13
|
-
export * from './layout-presets';
|
|
14
|
-
export * from './login-form';
|
|
15
|
-
export * from './main-login';
|
|
16
|
-
export * from './otp-verification';
|
|
5
|
+
export * from './auth';
|
|
6
|
+
export * from './components';
|
|
17
7
|
export * from './pages';
|
|
18
|
-
export * from './repeat-login';
|
|
19
|
-
export * from './signup-form';
|
|
20
|
-
export * from './sso-session';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-specific types: props, form values, hook options/return types.
|
|
3
|
+
*/
|
|
4
|
+
export * from './pages';
|
|
5
|
+
export * from './login-form';
|
|
6
|
+
export * from './signup-form';
|
|
7
|
+
export * from './otp-verification';
|
|
8
|
+
export * from './main-login';
|
|
9
|
+
export * from './repeat-login';
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { loginEmailFormSchema, loginPhoneFormSchema } from '../../validations';
|
|
4
4
|
/** Login mode: phone number or email */
|
|
5
5
|
export type LoginEntryMode = 'phone' | 'email';
|
|
6
|
+
/** Form values for phone-based login, inferred from the Zod schema. */
|
|
6
7
|
export type PhoneFormValues = z.infer<typeof loginPhoneFormSchema>;
|
|
8
|
+
/** Form values for email-based login, inferred from the Zod schema. */
|
|
7
9
|
export type EmailFormValues = z.infer<typeof loginEmailFormSchema>;
|
|
10
|
+
/** Discriminated union of phone or email login form values. */
|
|
8
11
|
export type LoginEntryFormValues = PhoneFormValues | EmailFormValues;
|
|
9
12
|
/** Payload when login entry form is valid (phone or email). */
|
|
10
13
|
export type LoginEntrySubmitData = {
|
|
@@ -32,15 +35,19 @@ export interface UseLoginEntryFormOptions {
|
|
|
32
35
|
* When provided, hook runs business logic: validate → call submitApi(data) → onSuccess(params).
|
|
33
36
|
* Use from consumer (e.g. Next.js): submitApi = sendOtp, onSuccess = (params) => router.push(`/otp?mode=${params.mode}&recipient=${encodeURIComponent(params.recipient)}`).
|
|
34
37
|
*/
|
|
35
|
-
submitApi?: (data: LoginEntrySubmitData) => Promise<void
|
|
38
|
+
submitApi?: ((data: LoginEntrySubmitData) => Promise<void>) | undefined;
|
|
36
39
|
/** Called after submitApi resolves successfully; receives mode and recipient for OTP redirect/display. */
|
|
37
|
-
onSuccess?: (params: LoginEntrySuccessParams) => void;
|
|
40
|
+
onSuccess?: ((params: LoginEntrySuccessParams) => void) | undefined;
|
|
38
41
|
/** Called when submitApi rejects or throws. */
|
|
39
|
-
onError?: (error: unknown) => void;
|
|
42
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
40
43
|
}
|
|
44
|
+
/** Return value of the `useLoginEntryForm` hook, providing form state and mode info. */
|
|
41
45
|
export interface UseLoginEntryFormReturn {
|
|
46
|
+
/** react-hook-form methods bound to the current login mode's schema. */
|
|
42
47
|
methods: UseFormReturn<LoginEntryFormValues>;
|
|
48
|
+
/** Submit handler to pass to the form's `onSubmit`. Validates and dispatches the login data. */
|
|
43
49
|
handleSubmit: (data: LoginEntryFormValues) => void;
|
|
50
|
+
/** True when the current mode is `'phone'`; use for conditional field rendering. */
|
|
44
51
|
isPhone: boolean;
|
|
45
52
|
/** True when current form values pass validation (for disabling Continue until valid – edge cases 3, 4). */
|
|
46
53
|
isFormValid: (data: LoginEntryFormValues) => boolean;
|
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
/** Handlers exposed by the main auth page (method select). */
|
|
2
2
|
export interface MainAuthPageHandlers {
|
|
3
|
+
/** Called when the user selects "Continue with Mobile". */
|
|
3
4
|
onContinueWithMobile: () => void;
|
|
5
|
+
/** Called when the user selects "Continue with Email". */
|
|
4
6
|
onContinueWithEmail: () => void;
|
|
7
|
+
/** Called when the user selects "Continue with Google". */
|
|
5
8
|
onContinueWithGoogle: () => void;
|
|
9
|
+
/** Called when the user selects "Continue with Apple". */
|
|
6
10
|
onContinueWithApple: () => void;
|
|
7
11
|
}
|
|
8
12
|
/** Config for lib-handled Google sign-in. When set, the lib runs the OAuth flow and calls onCredential. */
|
|
9
13
|
export interface MainLoginGoogleProviderConfig {
|
|
14
|
+
/** Google OAuth 2.0 client ID. */
|
|
10
15
|
clientId: string;
|
|
11
16
|
/** Called with ID token (One Tap) or auth code (button popup). Send to your backend to verify. */
|
|
12
17
|
onCredential: (credential: string) => void;
|
|
18
|
+
/** Enable Google One Tap prompt for automatic sign-in. */
|
|
13
19
|
enableOneTap?: boolean;
|
|
14
20
|
}
|
|
15
21
|
/** Config for lib-handled Apple sign-in (stub). When set, the lib will run the flow and call onCredential when implemented. */
|
|
16
22
|
export interface MainLoginAppleProviderConfig {
|
|
23
|
+
/** Apple Services ID (client ID) configured in the Apple Developer portal. */
|
|
17
24
|
clientId: string;
|
|
25
|
+
/** OAuth redirect URI registered with Apple for the sign-in flow. */
|
|
18
26
|
redirectUri: string;
|
|
27
|
+
/** Called with the Apple identity token after a successful sign-in. Send to your backend to verify. */
|
|
19
28
|
onCredential: (credential: string) => void;
|
|
20
29
|
}
|
|
21
30
|
/** Optional provider config so the lib handles Google/Apple API calls. */
|
|
22
31
|
export interface MainLoginPageProvidersConfig {
|
|
32
|
+
/** Google sign-in configuration. When set, the lib handles the Google OAuth flow. */
|
|
23
33
|
google?: MainLoginGoogleProviderConfig;
|
|
34
|
+
/** Apple sign-in configuration. When set, the lib handles the Apple OAuth flow. */
|
|
24
35
|
apple?: MainLoginAppleProviderConfig;
|
|
25
36
|
}
|
|
26
37
|
/** Options for useMainAuthPageHandlers: optional callback overrides + optional provider config for lib-handled OAuth. */
|
|
@@ -1,29 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { OtpVerificationMode, otpFormSchema } from '../../validations';
|
|
4
4
|
export type { OtpVerificationMode };
|
|
5
|
+
/** Form values for the OTP verification form, inferred from the Zod schema. */
|
|
5
6
|
export type OtpFormValues = z.infer<typeof otpFormSchema>;
|
|
7
|
+
/** Options for the `useOtpVerification` hook controlling mode, submission, and callbacks. */
|
|
6
8
|
export interface UseOtpVerificationOptions {
|
|
7
9
|
/** OTP mode: phone (60s cooldown) or email (2 min cooldown). */
|
|
8
10
|
mode: OtpVerificationMode;
|
|
9
11
|
/** Sync callback with OTP string. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
|
|
10
12
|
onSubmit?: ((otp: string) => void) | undefined;
|
|
13
|
+
/** Called when the user requests a new OTP code (resend). Ignored when submitApi is provided. */
|
|
11
14
|
onResendCode?: (() => void) | undefined;
|
|
12
15
|
/** When provided, hook runs: validate → submitApi(otp) → onSuccess(). Consumer passes redirect in onSuccess. */
|
|
13
|
-
submitApi?: (otp: string) => Promise<void
|
|
16
|
+
submitApi?: ((otp: string) => Promise<void>) | undefined;
|
|
14
17
|
/** Called after submitApi resolves (e.g. router.push('/dashboard')). */
|
|
15
|
-
onSuccess?: () => void;
|
|
18
|
+
onSuccess?: (() => void) | undefined;
|
|
16
19
|
/** Called when submitApi rejects or throws. */
|
|
17
|
-
onError?: (error: unknown) => void;
|
|
20
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
18
21
|
}
|
|
22
|
+
/** Return value of the `useOtpVerification` hook, providing form state and resend controls. */
|
|
19
23
|
export interface UseOtpVerificationReturn {
|
|
24
|
+
/** react-hook-form methods bound to the OTP form. */
|
|
20
25
|
methods: UseFormReturn<OtpFormValues>;
|
|
26
|
+
/** Submit handler to pass to the form's `onSubmit`. Validates and dispatches the OTP. */
|
|
21
27
|
handleSubmit: (data: OtpFormValues) => void;
|
|
22
28
|
/** True when current form values pass validation (for disabling Submit until valid – edge case 6). */
|
|
23
29
|
isFormValid: (data: OtpFormValues) => boolean;
|
|
30
|
+
/** Triggers a resend of the OTP code and resets the cooldown timer. */
|
|
24
31
|
handleResend: () => void;
|
|
32
|
+
/** Seconds remaining before the user can request another OTP code. */
|
|
25
33
|
resendSecondsLeft: number;
|
|
34
|
+
/** True when the resend cooldown has elapsed and the user may request a new code. */
|
|
26
35
|
canResend: boolean;
|
|
36
|
+
/** Human-readable countdown string (e.g. `"00:45"`) for display next to the resend button. */
|
|
27
37
|
timerText: string;
|
|
28
38
|
/** True while submitApi is in flight. */
|
|
29
39
|
isSubmitting: boolean;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import type { LoginEntryMode } from './login-form';
|
|
7
|
-
import type { UseMainAuthPageHandlersOptions } from './main-login';
|
|
8
|
-
import type { OtpVerificationMode } from './otp-verification';
|
|
1
|
+
import { UserType } from '../auth/auth-types';
|
|
2
|
+
import { IdentifierType } from '../auth/flow';
|
|
3
|
+
import { LoginEntryMode } from './login-form';
|
|
4
|
+
import { UseMainAuthPageHandlersOptions } from './main-login';
|
|
5
|
+
import { OtpVerificationMode } from './otp-verification';
|
|
9
6
|
/** Props for MainLoginPage and MainLogin components. */
|
|
10
7
|
export type MainLoginPageProps = UseMainAuthPageHandlersOptions;
|
|
11
8
|
/** Props for LoginEntry (inner form without layout). */
|
|
@@ -22,25 +19,25 @@ export interface LoginEntryProps {
|
|
|
22
19
|
* Sync callback with valid data. Use when parent owns API (e.g. AuthFlow).
|
|
23
20
|
* Ignored when submitApi is provided.
|
|
24
21
|
*/
|
|
25
|
-
onSubmit?: (data: {
|
|
22
|
+
onSubmit?: ((data: {
|
|
26
23
|
phone?: string;
|
|
27
24
|
email?: string;
|
|
28
|
-
}) => void;
|
|
25
|
+
}) => void) | undefined;
|
|
29
26
|
/**
|
|
30
27
|
* Async API call (e.g. send OTP). When provided, hook runs: validate → submitApi(data) → onSuccess().
|
|
31
28
|
* Consumer (e.g. Next.js) can pass redirect in onSuccess.
|
|
32
29
|
*/
|
|
33
|
-
submitApi?: (data: {
|
|
30
|
+
submitApi?: ((data: {
|
|
34
31
|
phone?: string;
|
|
35
32
|
email?: string;
|
|
36
|
-
}) => Promise<void
|
|
33
|
+
}) => Promise<void>) | undefined;
|
|
37
34
|
/** Called after submitApi succeeds; receives { mode, recipient } for OTP redirect/recipientDisplay. */
|
|
38
|
-
onSuccess?: (params: {
|
|
35
|
+
onSuccess?: ((params: {
|
|
39
36
|
mode: LoginEntryMode;
|
|
40
37
|
recipient: string;
|
|
41
|
-
}) => void;
|
|
38
|
+
}) => void) | undefined;
|
|
42
39
|
/** Called when submitApi fails. */
|
|
43
|
-
onError?: (error: unknown) => void;
|
|
40
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
44
41
|
}
|
|
45
42
|
/** Props for the full LoginEntryPage (adds optional layout overrides for story/viewport). */
|
|
46
43
|
export interface LoginEntryPageProps extends LoginEntryProps {
|
|
@@ -58,23 +55,23 @@ export interface SignupPageProps {
|
|
|
58
55
|
/** Indian only: which field to collect (phone or email). */
|
|
59
56
|
signupCollectField: IdentifierType;
|
|
60
57
|
/** Foreign only: phone when user entered phone before signup details. */
|
|
61
|
-
pendingPhone?: string;
|
|
58
|
+
pendingPhone?: string | undefined;
|
|
62
59
|
/** Sync callback with valid data. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
|
|
63
|
-
onSubmit?: (data: {
|
|
60
|
+
onSubmit?: ((data: {
|
|
64
61
|
fullName: string;
|
|
65
62
|
phone?: string;
|
|
66
63
|
email?: string;
|
|
67
|
-
}) => void;
|
|
64
|
+
}) => void) | undefined;
|
|
68
65
|
/** Async API (e.g. complete profile). When provided, hook runs: validate → submitApi(data) → onSuccess(). */
|
|
69
|
-
submitApi?: (data: {
|
|
66
|
+
submitApi?: ((data: {
|
|
70
67
|
fullName: string;
|
|
71
68
|
phone?: string;
|
|
72
69
|
email?: string;
|
|
73
|
-
}) => Promise<void
|
|
70
|
+
}) => Promise<void>) | undefined;
|
|
74
71
|
/** Called after submitApi succeeds (e.g. router.push('/otp') or next step). */
|
|
75
|
-
onSuccess?: () => void;
|
|
72
|
+
onSuccess?: (() => void) | undefined;
|
|
76
73
|
/** Called when submitApi fails. */
|
|
77
|
-
onError?: (error: unknown) => void;
|
|
74
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
78
75
|
}
|
|
79
76
|
/** Props for the full SignupPage (adds optional layout overrides). */
|
|
80
77
|
export interface SignupPageFullProps extends SignupPageProps {
|
|
@@ -86,23 +83,23 @@ export interface OtpVerificationProps {
|
|
|
86
83
|
/** Mode: mobile (phone) or email OTP */
|
|
87
84
|
mode: OtpVerificationMode;
|
|
88
85
|
/** Title override. Default: "6 digit OTP has been sent to your Mobile" | "..." Email */
|
|
89
|
-
title?: string;
|
|
86
|
+
title?: string | undefined;
|
|
90
87
|
/** Masked phone (e.g. "+91 9825910X0X") or email (e.g. "j***@gmail.com") */
|
|
91
88
|
recipientDisplay: string;
|
|
92
89
|
/** When true, show instruction line ("Kindly check your Email Inbox."). Used for foreign user flow. */
|
|
93
|
-
isForeignUser?: boolean;
|
|
90
|
+
isForeignUser?: boolean | undefined;
|
|
94
91
|
/** Handler when back is clicked */
|
|
95
|
-
onBack?: () => void;
|
|
92
|
+
onBack?: (() => void) | undefined;
|
|
96
93
|
/** Sync callback with OTP. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
|
|
97
|
-
onSubmit?: (otp: string) => void;
|
|
94
|
+
onSubmit?: ((otp: string) => void) | undefined;
|
|
98
95
|
/** Handler when user requests resend code */
|
|
99
|
-
onResendCode?: () => void;
|
|
96
|
+
onResendCode?: (() => void) | undefined;
|
|
100
97
|
/** Async API (e.g. verify OTP). When provided, hook runs: validate → submitApi(otp) → onSuccess(). */
|
|
101
|
-
submitApi?: (otp: string) => Promise<void
|
|
98
|
+
submitApi?: ((otp: string) => Promise<void>) | undefined;
|
|
102
99
|
/** Called after submitApi succeeds (e.g. router.push('/dashboard')). */
|
|
103
|
-
onSuccess?: () => void;
|
|
100
|
+
onSuccess?: (() => void) | undefined;
|
|
104
101
|
/** Called when submitApi fails. */
|
|
105
|
-
onError?: (error: unknown) => void;
|
|
102
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
106
103
|
}
|
|
107
104
|
/** Props for the full OtpVerificationPage (adds optional layout overrides). */
|
|
108
105
|
export interface OtpVerificationPageProps extends OtpVerificationProps {
|
|
@@ -119,15 +116,15 @@ export interface RepeatLoginProps {
|
|
|
119
116
|
*/
|
|
120
117
|
lastUsedMethod?: string;
|
|
121
118
|
/** Sync handler for primary action. Use when caller owns API (e.g. AuthFlow). Ignored when continueApi is provided. */
|
|
122
|
-
onContinueWithLastMethod?: () => void;
|
|
119
|
+
onContinueWithLastMethod?: (() => void) | undefined;
|
|
123
120
|
/** Handler for the secondary action (choose another method). */
|
|
124
|
-
onUseAnotherMethod?: () => void;
|
|
121
|
+
onUseAnotherMethod?: (() => void) | undefined;
|
|
125
122
|
/** Async API for continue (e.g. validate session). When provided, hook runs: continueApi() → onSuccess(). */
|
|
126
|
-
continueApi?: () => Promise<void
|
|
123
|
+
continueApi?: (() => Promise<void>) | undefined;
|
|
127
124
|
/** Called after continueApi succeeds (e.g. router.push('/dashboard')). */
|
|
128
|
-
onSuccess?: () => void;
|
|
125
|
+
onSuccess?: (() => void) | undefined;
|
|
129
126
|
/** Called when continueApi fails. */
|
|
130
|
-
onError?: (error: unknown) => void;
|
|
127
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
131
128
|
}
|
|
132
129
|
/** Props for the full RepeatLoginPage (adds optional layout overrides). */
|
|
133
130
|
export interface RepeatLoginPageProps extends RepeatLoginProps {
|
|
@@ -6,18 +6,19 @@ export interface UseRepeatLoginOptions {
|
|
|
6
6
|
* Last used authentication method shown in the primary button label.
|
|
7
7
|
* @default "Mobile"
|
|
8
8
|
*/
|
|
9
|
-
lastUsedMethod?: string;
|
|
9
|
+
lastUsedMethod?: string | undefined;
|
|
10
10
|
/** Sync handler for primary action. Use when caller owns API (e.g. AuthFlow). Ignored when continueApi is provided. */
|
|
11
|
-
onContinueWithLastMethod?: () => void;
|
|
11
|
+
onContinueWithLastMethod?: (() => void) | undefined;
|
|
12
12
|
/** Handler for the secondary action (choose another method). */
|
|
13
|
-
onUseAnotherMethod?: () => void;
|
|
13
|
+
onUseAnotherMethod?: (() => void) | undefined;
|
|
14
14
|
/** Async API for continue (e.g. validate session). When provided, hook runs: continueApi() → onSuccess(). */
|
|
15
|
-
continueApi?: () => Promise<void
|
|
15
|
+
continueApi?: (() => Promise<void>) | undefined;
|
|
16
16
|
/** Called after continueApi succeeds (e.g. router.push('/dashboard')). */
|
|
17
|
-
onSuccess?: () => void;
|
|
17
|
+
onSuccess?: (() => void) | undefined;
|
|
18
18
|
/** Called when continueApi fails. */
|
|
19
|
-
onError?: (error: unknown) => void;
|
|
19
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
20
20
|
}
|
|
21
|
+
/** Return value of the `useRepeatLogin` hook, providing continue handler and display state. */
|
|
21
22
|
export interface UseRepeatLoginReturn {
|
|
22
23
|
/** Call this when the user clicks "Continue with {lastUsedMethod}". */
|
|
23
24
|
handleContinue: () => void;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { signupEmailFormSchema, signupForeignFormSchema, signupPhoneFormSchema } from '../../validations';
|
|
4
4
|
/** Signup mode: phone, email as second field, or foreign (full name + email + phone). */
|
|
5
5
|
export type SignupEntryMode = 'phone' | 'email' | 'foreign';
|
|
6
|
+
/** Form values for phone-based signup, inferred from the Zod schema. */
|
|
6
7
|
export type SignupPhoneFormValues = z.infer<typeof signupPhoneFormSchema>;
|
|
8
|
+
/** Form values for email-based signup, inferred from the Zod schema. */
|
|
7
9
|
export type SignupEmailFormValues = z.infer<typeof signupEmailFormSchema>;
|
|
10
|
+
/** Form values for foreign signup (full name + email + phone), inferred from the Zod schema. */
|
|
8
11
|
export type SignupForeignFormValues = z.infer<typeof signupForeignFormSchema>;
|
|
12
|
+
/** Discriminated union of all signup form value shapes. */
|
|
9
13
|
export type SignupFormValues = SignupPhoneFormValues | SignupEmailFormValues | SignupForeignFormValues;
|
|
10
14
|
/** Payload when signup form is valid. */
|
|
11
15
|
export type SignupSubmitData = {
|
|
@@ -17,18 +21,21 @@ export interface UseSignupFormOptions {
|
|
|
17
21
|
/** Mode: phone, email as second field, or foreign (name + email + phone) */
|
|
18
22
|
mode: SignupEntryMode;
|
|
19
23
|
/** For foreign mode: pre-fill phone when user already entered it. */
|
|
20
|
-
defaultPhone?: string;
|
|
24
|
+
defaultPhone?: string | undefined;
|
|
21
25
|
/** Sync callback with valid data. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
|
|
22
26
|
onSubmit?: ((data: SignupSubmitData) => void) | undefined;
|
|
23
27
|
/** When provided, hook runs: validate → submitApi(data) → onSuccess(). Consumer passes redirect in onSuccess. */
|
|
24
|
-
submitApi?: (data: SignupSubmitData) => Promise<void
|
|
28
|
+
submitApi?: ((data: SignupSubmitData) => Promise<void>) | undefined;
|
|
25
29
|
/** Called after submitApi succeeds (e.g. router.push('/otp') or next step). */
|
|
26
|
-
onSuccess?: () => void;
|
|
30
|
+
onSuccess?: (() => void) | undefined;
|
|
27
31
|
/** Called when submitApi rejects or throws. */
|
|
28
|
-
onError?: (error: unknown) => void;
|
|
32
|
+
onError?: ((error: unknown) => void) | undefined;
|
|
29
33
|
}
|
|
34
|
+
/** Return value of the `useSignupForm` hook, providing form state and mode flags. */
|
|
30
35
|
export interface UseSignupFormReturn {
|
|
36
|
+
/** react-hook-form methods bound to the current signup mode's schema. */
|
|
31
37
|
methods: UseFormReturn<SignupFormValues>;
|
|
38
|
+
/** Submit handler to pass to the form's `onSubmit`. Validates and dispatches signup data. */
|
|
32
39
|
handleSubmit: (data: SignupFormValues) => void;
|
|
33
40
|
/** True when mode is 'phone', false when mode is 'email'. For 'foreign' same as (mode === 'phone') for layout. */
|
|
34
41
|
isPhone: boolean;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized Zod schemas for auth forms (signup, login, OTP).
|
|
3
|
-
* Single source of truth for validation rules per PRODUCT_PROTOCOLS.
|
|
4
|
-
*/
|
|
5
1
|
import { z } from 'zod';
|
|
6
2
|
/** Capitalize first letter of each word (PRODUCT_PROTOCOLS #25 – Naming conventions). */
|
|
7
3
|
export declare function capitalizeWords(value: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doct-ui-auth-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"dev": "vite",
|
|
26
|
-
"build": "tsc -b && vite build
|
|
26
|
+
"build": "tsc -b && vite build",
|
|
27
27
|
"prepublishOnly": "npm run build",
|
|
28
28
|
"lint": "biome lint .",
|
|
29
29
|
"preview": "vite preview",
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { LoginEntryPageProps, LoginEntryProps } from '@/types';
|
|
2
|
-
export type { LoginEntryMode, LoginEntryPageProps, LoginEntryProps, } from '@/types';
|
|
3
|
-
/**
|
|
4
|
-
* Full LoginEntry page with AuthLayoutWrapper, back button, and slider/standalone layout.
|
|
5
|
-
* Use when rendering the login entry screen as a standalone page.
|
|
6
|
-
*
|
|
7
|
-
* @example Next.js: API call in hook, redirect with mode + recipient for OTP page
|
|
8
|
-
* ```tsx
|
|
9
|
-
* <LoginEntryPage
|
|
10
|
-
* mode="phone"
|
|
11
|
-
* onBack={() => router.back()}
|
|
12
|
-
* submitApi={(data) => api.sendOtp(data)}
|
|
13
|
-
* onSuccess={(params) => router.push(`/otp?mode=${params.mode}&recipient=${encodeURIComponent(params.recipient)}`)}
|
|
14
|
-
* />
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @example Sync callback (caller owns API)
|
|
18
|
-
* ```tsx
|
|
19
|
-
* <LoginEntryPage mode="phone" onSubmit={(data) => sendOtp(data)} />
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare function LoginEntryPage(props: Readonly<LoginEntryPageProps>): import("react/jsx-runtime").JSX.Element;
|
|
23
|
-
/**
|
|
24
|
-
* Login entry form body without layout wrapper.
|
|
25
|
-
* Single form for phone or email based on mode. Use inside your own layout or AuthFlow.
|
|
26
|
-
* Validation per PRODUCT_PROTOCOLS and edge cases 3–5, 18; cursor focus on first field (#26).
|
|
27
|
-
*
|
|
28
|
-
* @example With AuthFlow (sync onSubmit)
|
|
29
|
-
* ```tsx
|
|
30
|
-
* <LoginEntry mode="phone" onSubmit={(data) => actions.submitIdentifier(data)} />
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @example Standalone Next.js (API + redirect in hook)
|
|
34
|
-
* ```tsx
|
|
35
|
-
* <LoginEntry
|
|
36
|
-
* mode="phone"
|
|
37
|
-
* submitApi={(data) => api.sendOtp(data)}
|
|
38
|
-
* onSuccess={() => router.push('/otp')}
|
|
39
|
-
* />
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function LoginEntry(props: Readonly<LoginEntryProps>): import("react/jsx-runtime").JSX.Element;
|