@saxenapackages/auth-sdk 1.0.0
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/README.md +195 -0
- package/dist/api/authApi.d.ts +19 -0
- package/dist/api/axios.d.ts +5 -0
- package/dist/auth-sdk.css +1 -0
- package/dist/components/alert/Alert.d.ts +9 -0
- package/dist/components/authWidget/index.d.ts +7 -0
- package/dist/components/forgotPassword/index.d.ts +8 -0
- package/dist/components/googleLogin/index.d.ts +7 -0
- package/dist/components/login/index.d.ts +9 -0
- package/dist/components/otp/index.d.ts +12 -0
- package/dist/components/resetPassword/index.d.ts +8 -0
- package/dist/components/signup/index.d.ts +8 -0
- package/dist/components/updateUser/index.d.ts +9 -0
- package/dist/hooks/useAuth.d.ts +3 -0
- package/dist/hooks/useLogin.d.ts +8 -0
- package/dist/hooks/useOtp.d.ts +9 -0
- package/dist/hooks/useResetPassword.d.ts +8 -0
- package/dist/hooks/useSignup.d.ts +8 -0
- package/dist/hooks/useUpdateUser.d.ts +8 -0
- package/dist/hooks/useVerifyIdentity.d.ts +8 -0
- package/dist/index.cjs +23 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +2248 -0
- package/dist/index.js.map +1 -0
- package/dist/provider/AuthContext.d.ts +24 -0
- package/dist/provider/AuthProvider.d.ts +8 -0
- package/dist/services/event.service.d.ts +9 -0
- package/dist/services/storage.service.d.ts +10 -0
- package/dist/services/token.service.d.ts +10 -0
- package/dist/setupTests.d.ts +0 -0
- package/dist/theme/defaultTheme.d.ts +3 -0
- package/dist/types/api.d.ts +10 -0
- package/dist/types/auth.d.ts +28 -0
- package/dist/types/config.d.ts +139 -0
- package/dist/utils/errors.d.ts +7 -0
- package/dist/utils/helpers.d.ts +8 -0
- package/dist/validation/index.d.ts +6 -0
- package/dist/validation/login.d.ts +28 -0
- package/dist/validation/otp.d.ts +8 -0
- package/dist/validation/resetPassword.d.ts +17 -0
- package/dist/validation/signup.d.ts +27 -0
- package/dist/validation/updateUser.d.ts +38 -0
- package/dist/validation/verifyIdentity.d.ts +8 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Premium React Authentication SDK
|
|
2
|
+
|
|
3
|
+
A production-grade, highly customizable React Authentication SDK similar to Clerk, Auth0, or Firebase Auth UI.
|
|
4
|
+
|
|
5
|
+
This SDK features support for config-based REST APIs, custom endpoint schemas, auto-refresh tokens, event-driven event systems, modular components overrides, and beautiful Light/Dark/Custom themes.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Seamless Token Management**: Auto-silent token refresh, refresh locks, dynamic authorization headers.
|
|
12
|
+
- **Custom Backend Compatibility**: Configuration-based dynamic request and response mapping (`responseMapping` and `requestMapping`).
|
|
13
|
+
- **Flexible Storage**: Dynamic support for `localStorage`, `sessionStorage`, in-memory, or custom storage adapters.
|
|
14
|
+
- **Polished UX/Theming**: Out-of-the-box support for Light, Dark, or Custom HSL palettes, glassmorphism, responsive grid layout, and micro-animations.
|
|
15
|
+
- **Components Overrides**: Replace any button, card, input, loading animation, or checkbox dynamically.
|
|
16
|
+
- **Robust Event Bus**: Subscribe to authentication lifecycles (`LOGIN_SUCCESS`, `LOGOUT`, `TOKEN_EXPIRED`, `OTP_SENT`) from your root application code.
|
|
17
|
+
- **Accessibility & Security**: Complies with WAI-ARIA standards, keyboard tabIndex navigation, automatic logout on token expiry, and token renew queuing.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Install using npm:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install auth-sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or pnpm:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm add auth-sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### 1. Initialize `AuthProvider`
|
|
40
|
+
|
|
41
|
+
Wrap your React application in `<AuthProvider>` and supply your API configurations:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import React from 'react';
|
|
45
|
+
import ReactDOM from 'react-dom/client';
|
|
46
|
+
import { AuthProvider } from 'auth-sdk';
|
|
47
|
+
import App from './App';
|
|
48
|
+
|
|
49
|
+
const sdkConfig = {
|
|
50
|
+
apiBaseUrl: 'https://api.yourdomain.com',
|
|
51
|
+
site: 'localhost', // Optional identifier
|
|
52
|
+
endpoints: {
|
|
53
|
+
login: '/identity/signin',
|
|
54
|
+
signup: '/identity/signup',
|
|
55
|
+
verifyIdentity: '/identity/verify',
|
|
56
|
+
verifyOtp: '/identity/verify-otp',
|
|
57
|
+
resetPassword: '/identity/update',
|
|
58
|
+
refreshToken: '/identity/access-token',
|
|
59
|
+
logout: '/identity/signout'
|
|
60
|
+
},
|
|
61
|
+
storage: 'localStorage',
|
|
62
|
+
tokenKey: 'accessToken',
|
|
63
|
+
refreshTokenKey: 'refreshToken',
|
|
64
|
+
theme: 'dark',
|
|
65
|
+
enableRefreshToken: true,
|
|
66
|
+
autoRefresh: true
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
70
|
+
<AuthProvider config={sdkConfig}>
|
|
71
|
+
<App />
|
|
72
|
+
</AuthProvider>
|
|
73
|
+
);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 2. Render AuthWidget Component
|
|
77
|
+
|
|
78
|
+
To get up and running quickly, use the unified `AuthWidget` component. It handles the complete router flows internally (Login, Sign Up, Verify Identity, OTP verification, and Password Reset) with zero boilerplate:
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import React from 'react';
|
|
82
|
+
import { AuthWidget } from 'auth-sdk';
|
|
83
|
+
|
|
84
|
+
export default function AuthPage() {
|
|
85
|
+
return (
|
|
86
|
+
<div className="auth-container">
|
|
87
|
+
<AuthWidget
|
|
88
|
+
view="login" // 'login' | 'signup' | 'forgotPassword' | 'otp' | 'resetPassword' | 'updateUser'
|
|
89
|
+
onSuccess={(view, data) => {
|
|
90
|
+
console.log(`Action succeeded in view "${view}":`, data);
|
|
91
|
+
}}
|
|
92
|
+
/>
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Deep Dive Documentation
|
|
101
|
+
|
|
102
|
+
### 1. Unified AuthWidget Routing Flow
|
|
103
|
+
|
|
104
|
+
The `AuthWidget` has built-in event listeners connected directly to the SDK. Here is how navigation flows:
|
|
105
|
+
|
|
106
|
+
```mermaid
|
|
107
|
+
graph TD
|
|
108
|
+
A[Login Card] -->|Forgot Password Click| B[ForgotPassword Card]
|
|
109
|
+
A -->|Signup Click| C[Signup Card]
|
|
110
|
+
C -->|API: OTP Sent / Unverified User| D[OTP Verification Card]
|
|
111
|
+
B -->|API: OTP Sent| D
|
|
112
|
+
D -->|API: Validated Reset Token| E[Reset Password Card]
|
|
113
|
+
E -->|API: Password Updated| A
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
All token transitions, error banners with auto-dismiss (5 seconds), and user validations are automated.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### 2. Custom Payload Configuration
|
|
121
|
+
|
|
122
|
+
If your backend API expects different field names or outputs a nested payload, you can map them in `config`:
|
|
123
|
+
|
|
124
|
+
#### Request Mapping (Inputs to API Payload)
|
|
125
|
+
```typescript
|
|
126
|
+
const requestMapping = {
|
|
127
|
+
login: {
|
|
128
|
+
email: 'email',
|
|
129
|
+
password: 'password'
|
|
130
|
+
},
|
|
131
|
+
signup: {
|
|
132
|
+
name: 'fullName',
|
|
133
|
+
email: 'email',
|
|
134
|
+
password: 'password'
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
```
|
|
138
|
+
*Note: The keys on the left **must** be camelCase matching the internal SDK models, and the values are whatever key your backend expects.*
|
|
139
|
+
|
|
140
|
+
#### Response Mapping (API Output to SDK Session)
|
|
141
|
+
```typescript
|
|
142
|
+
const responseMapping = {
|
|
143
|
+
token: 'accessToken',
|
|
144
|
+
refreshToken: 'refreshToken',
|
|
145
|
+
user: 'userProfile' // Supports nested dot notation (e.g. 'result.user')
|
|
146
|
+
};
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
### 3. Event Bus Subscriptions
|
|
152
|
+
|
|
153
|
+
You can subscribe to lifecycle hooks globally using `eventService` to sync your external application state (e.g., custom routers or analytics):
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
import { useEffect } from 'react';
|
|
157
|
+
import { eventService } from 'auth-sdk';
|
|
158
|
+
|
|
159
|
+
function App() {
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
// Listen to events
|
|
162
|
+
const handleLoginSuccess = (data) => console.log('User signed in!', data);
|
|
163
|
+
const handleOtpSent = (data) => console.log('OTP dispatched to user e-mail!');
|
|
164
|
+
|
|
165
|
+
eventService.on('LOGIN_SUCCESS', handleLoginSuccess);
|
|
166
|
+
eventService.on('OTP_SENT', handleOtpSent);
|
|
167
|
+
|
|
168
|
+
return () => {
|
|
169
|
+
eventService.off('LOGIN_SUCCESS', handleLoginSuccess);
|
|
170
|
+
eventService.off('OTP_SENT', handleOtpSent);
|
|
171
|
+
};
|
|
172
|
+
}, []);
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### Available Events:
|
|
177
|
+
* `LOGIN_SUCCESS`: Fired on successful login session creation.
|
|
178
|
+
* `LOGIN_FAILED`: Fired on authentication validation errors.
|
|
179
|
+
* `LOGOUT`: Fired when the active session is destroyed.
|
|
180
|
+
* `OTP_SENT`: Fired when an OTP code is generated or required during login/registration.
|
|
181
|
+
* `OTP_VERIFIED`: Fired when OTP code is successfully validated.
|
|
182
|
+
* `PASSWORD_RESET`: Fired when credentials have been updated successfully.
|
|
183
|
+
* `TOKEN_EXPIRED`: Fired when the refresh token expires and a silent renew fails.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Documentation Index
|
|
188
|
+
|
|
189
|
+
Detailed documentation for advanced SDK configuration and custom setup options can be found in the following documents:
|
|
190
|
+
|
|
191
|
+
1. [Configuration Guide (Configuration.md)](./docs/Configuration.md) - Deep dive into request/response mappings, storage adapters, and custom endpoints.
|
|
192
|
+
2. [Hooks Reference (Hooks.md)](./docs/Hooks.md) - API details for `useAuth`, `useLogin`, `useSignup`, `useOtp`, etc.
|
|
193
|
+
3. [API Services & Client (API.md)](./docs/API.md) - Axios client integration, error handling codes, and concurrent refresh queue behavior.
|
|
194
|
+
4. [Theming & Customization (Theme.md)](./docs/Theme.md) - Color overrides, custom components rendering, Dark mode integration, and translations.
|
|
195
|
+
5. [Migration Guide (Migration.md)](./docs/Migration.md) - Integrating the SDK from a custom local auth implementation.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { AuthSdkConfig } from '../types/config';
|
|
3
|
+
export declare class AuthApi {
|
|
4
|
+
private axiosInstance;
|
|
5
|
+
private config;
|
|
6
|
+
constructor(axiosInstance: AxiosInstance, config: AuthSdkConfig);
|
|
7
|
+
private getEndpoint;
|
|
8
|
+
private resolveUrl;
|
|
9
|
+
login(payload: Record<string, any>): Promise<any>;
|
|
10
|
+
signup(payload: Record<string, any>): Promise<any>;
|
|
11
|
+
verifyIdentity(payload: Record<string, any>, urlParams?: Record<string, string | number>): Promise<any>;
|
|
12
|
+
verifyOtp(payload: Record<string, any>, urlParams?: Record<string, string | number>): Promise<any>;
|
|
13
|
+
resetPassword(payload: Record<string, any>, urlParams?: Record<string, string | number>): Promise<any>;
|
|
14
|
+
googleLogin(userId: string): Promise<any>;
|
|
15
|
+
logout(): Promise<any>;
|
|
16
|
+
getUserProfile(site?: string, id?: string): Promise<any>;
|
|
17
|
+
updateUser(payload: Record<string, any>, site?: string, id?: string): Promise<any>;
|
|
18
|
+
deleteUser(site?: string, id?: string): Promise<any>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { AuthSdkConfig } from '../types/config';
|
|
3
|
+
import { TokenService } from '../services/token.service';
|
|
4
|
+
export declare function createAxiosInstance(config: AuthSdkConfig, tokenService: TokenService, onTokenRefreshed: (token: string, refreshToken?: string) => void, onSessionExpired: () => void): AxiosInstance;
|
|
5
|
+
export default createAxiosInstance;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
._card_1gys8_2{box-sizing:border-box;background:var(--auth-color-surface, #ffffff);border:1px solid var(--auth-color-border, #e2e8f0);border-radius:var(--auth-border-radius-card, var(--auth-border-radius, 8px));padding:calc(var(--auth-spacing) * 2);width:100%;max-width:440px;box-shadow:0 20px 25px -5px #0000000d,0 10px 10px -5px #00000008,0 0 0 1px #00000008;font-family:var(--auth-font-body, system-ui, -apple-system, sans-serif);color:var(--auth-color-text, #1f2937);margin:0 auto;transition:all .25s ease}._heading_1gys8_18{margin-top:0;margin-bottom:calc(var(--auth-spacing) * .3);font-family:var(--auth-font-heading, system-ui, -apple-system, sans-serif);font-size:1.625rem;font-weight:700;text-align:center;color:var(--auth-color-text, #1f2937);letter-spacing:-.02em}._subtext_1gys8_30{font-size:.875rem;color:var(--auth-color-text-muted, #6b7280);text-align:center;margin-bottom:calc(var(--auth-spacing) * 1.5);line-height:1.5}._form_1gys8_39{display:flex;flex-direction:column;gap:calc(var(--auth-spacing) * 1.1)}._formGroup_1gys8_45{display:flex;flex-direction:column;gap:6px;position:relative}._label_1gys8_52{font-size:.875rem;font-weight:500;color:var(--auth-color-text, #374151);text-align:left}._inputWrapper_1gys8_59{position:relative;display:flex;align-items:center;width:100%}._input_1gys8_59{box-sizing:border-box;width:100%;padding:10px 14px;font-size:.95rem;background:var(--auth-color-surface, #ffffff);color:var(--auth-color-text, #1f2937);border:1px solid var(--auth-color-border, #d1d5db);border-radius:var(--auth-border-radius-input, var(--auth-border-radius, 8px));outline:none;transition:all .2s ease}._input_1gys8_59::placeholder{color:#94a3b8!important;opacity:.85}._input_1gys8_59:focus{border-color:var(--auth-color-primary, #004ac6);box-shadow:0 0 0 3px #004ac61a}._inputError_1gys8_89{border-color:var(--auth-color-error, #ef4444)}._inputError_1gys8_89:focus{border-color:var(--auth-color-error, #ef4444);box-shadow:0 0 0 3px #ef44441a}._inputIcon_1gys8_98{position:absolute;right:14px;background:none;border:none;color:var(--auth-color-text-muted, #94a3b8);cursor:pointer;padding:0;display:flex;align-items:center;justify-content:center;transition:color .2s ease}._inputIcon_1gys8_98:hover{color:var(--auth-color-text, #1f2937)}._eyeIcon_1gys8_116{width:18px;height:18px}._errorText_1gys8_121{font-size:.8rem;color:var(--auth-color-error, #ef4444);margin-top:4px;display:flex;align-items:center;gap:4px}._button_1gys8_131{display:flex;align-items:center;justify-content:center;padding:11px;font-size:.95rem;font-weight:600;color:#fff;background:var(--auth-color-primary, #004ac6);border:none;border-radius:var(--auth-border-radius-button, var(--auth-border-radius, 8px));cursor:pointer;transition:all .2s ease}._button_1gys8_131:hover:not(:disabled){background:var(--auth-color-primary-hover, #003ba1)}._button_1gys8_131:active:not(:disabled){transform:scale(.99)}._button_1gys8_131:disabled{opacity:.6;cursor:not-allowed}._link_1gys8_160{font-size:.875rem;color:var(--auth-color-secondary, #ec4899);text-decoration:none;font-weight:500;transition:all .2s ease;cursor:pointer;background:none;border:none;padding:0}._link_1gys8_160:hover{opacity:.85;text-decoration:underline}._footerText_1gys8_177{font-size:.875rem;text-align:center;color:var(--auth-color-text-muted, #6b7280);margin-top:calc(var(--auth-spacing) * .5)}._divider_1gys8_185{display:flex;align-items:center;text-align:center;margin:calc(var(--auth-spacing) * .8) 0;color:var(--auth-color-text-muted, #6b7280);font-size:.813rem;font-weight:500}._divider_1gys8_185:before,._divider_1gys8_185:after{content:"";flex:1;border-bottom:1px solid var(--auth-color-border, #e2e8f0)}._divider_1gys8_185:not(:empty):before{margin-right:1em}._divider_1gys8_185:not(:empty):after{margin-left:1em}._googleButton_1gys8_211{display:flex;align-items:center;justify-content:center;gap:10px;padding:11px;font-size:.95rem;font-weight:500;background:#fff;color:#374151!important;border:1px solid var(--auth-color-border, #d1d5db);border-radius:var(--auth-border-radius-button, var(--auth-border-radius, 8px));cursor:pointer;transition:all .2s ease;width:100%}._googleButton_1gys8_211:hover{background:#f9fafb;border-color:#c3c6cb}._googleIcon_1gys8_233{width:18px;height:18px}._otpContainer_1gys8_239{display:flex;justify-content:space-between;gap:10px;margin:10px 0}._otpInput_1gys8_246{box-sizing:border-box;width:50px;height:50px;font-size:1.5rem;font-weight:700;text-align:center;background:var(--auth-color-surface, #ffffff);color:var(--auth-color-text, #1f2937);border:1px solid var(--auth-color-border, #d1d5db);border-radius:var(--auth-border-radius, 8px);outline:none;transition:all .2s ease}._otpInput_1gys8_246:focus{border-color:var(--auth-color-primary, #004ac6);box-shadow:0 0 0 3px #004ac61a}._apiErrorBlock_1gys8_267{box-sizing:border-box;display:flex;align-items:flex-start;gap:10px;padding:10px 14px;background:#ef444412;border:1px solid rgba(239,68,68,.18);border-left:4px solid var(--auth-color-error, #ef4444);border-radius:var(--auth-border-radius, 6px);color:var(--auth-color-error, #ef4444);font-size:.85rem;font-weight:500;line-height:1.4;margin-bottom:16px;text-align:left}._apiErrorIcon_1gys8_285{flex-shrink:0;width:16px;height:16px;margin-top:2px;color:var(--auth-color-error, #ef4444)}._apiSuccessBlock_1gys8_294{box-sizing:border-box;display:flex;align-items:flex-start;gap:10px;padding:10px 14px;background:#10b98112;border:1px solid rgba(16,185,129,.18);border-left:4px solid var(--auth-color-success, #10b981);border-radius:var(--auth-border-radius, 6px);color:var(--auth-color-success, #10b981);font-size:.85rem;font-weight:500;line-height:1.4;margin-bottom:16px;text-align:left}._apiSuccessIcon_1gys8_312{flex-shrink:0;width:16px;height:16px;margin-top:2px;color:var(--auth-color-success, #10b981)}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface AuthWidgetProps {
|
|
3
|
+
view?: 'login' | 'signup' | 'forgotPassword' | 'otp' | 'resetPassword' | 'updateUser';
|
|
4
|
+
onSuccess?: (view: string, data: any) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const AuthWidget: React.FC<AuthWidgetProps>;
|
|
7
|
+
export default AuthWidget;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { BaseComponentProps } from '../../types/auth';
|
|
3
|
+
export interface ForgotPasswordProps extends BaseComponentProps {
|
|
4
|
+
onSuccess?: (data: any) => void;
|
|
5
|
+
onBackToLoginClick?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const ForgotPassword: React.FC<ForgotPasswordProps>;
|
|
8
|
+
export default ForgotPassword;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { BaseComponentProps } from '../../types/auth';
|
|
3
|
+
export interface LoginProps extends BaseComponentProps {
|
|
4
|
+
onSuccess?: (data: any) => void;
|
|
5
|
+
onForgotPasswordClick?: () => void;
|
|
6
|
+
onSignupClick?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const Login: React.FC<LoginProps>;
|
|
9
|
+
export default Login;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { BaseComponentProps } from '../../types/auth';
|
|
3
|
+
export interface OTPProps extends BaseComponentProps {
|
|
4
|
+
email?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
urlParams?: Record<string, string | number>;
|
|
8
|
+
onSuccess?: (data: any) => void;
|
|
9
|
+
onResendSuccess?: (data: any) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const OTP: React.FC<OTPProps>;
|
|
12
|
+
export default OTP;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { BaseComponentProps } from '../../types/auth';
|
|
3
|
+
export interface ResetPasswordProps extends BaseComponentProps {
|
|
4
|
+
urlParams?: Record<string, string | number>;
|
|
5
|
+
onSuccess?: (data: any) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const ResetPassword: React.FC<ResetPasswordProps>;
|
|
8
|
+
export default ResetPassword;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { BaseComponentProps } from '../../types/auth';
|
|
3
|
+
export interface SignupProps extends BaseComponentProps {
|
|
4
|
+
onSuccess?: (data: any) => void;
|
|
5
|
+
onLoginClick?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const Signup: React.FC<SignupProps>;
|
|
8
|
+
export default Signup;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { BaseComponentProps } from '../../types/auth';
|
|
3
|
+
export interface UpdateUserProps extends BaseComponentProps {
|
|
4
|
+
onSuccess?: (data: any) => void;
|
|
5
|
+
site?: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const UpdateUser: React.FC<UpdateUserProps>;
|
|
9
|
+
export default UpdateUser;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function useOtp(): {
|
|
2
|
+
loading: boolean;
|
|
3
|
+
error: string | null;
|
|
4
|
+
success: boolean;
|
|
5
|
+
execute: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
|
|
6
|
+
resend: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
|
|
7
|
+
reset: () => void;
|
|
8
|
+
};
|
|
9
|
+
export default useOtp;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function useResetPassword(): {
|
|
2
|
+
loading: boolean;
|
|
3
|
+
error: string | null;
|
|
4
|
+
success: boolean;
|
|
5
|
+
execute: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
|
|
6
|
+
reset: () => void;
|
|
7
|
+
};
|
|
8
|
+
export default useResetPassword;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function useVerifyIdentity(): {
|
|
2
|
+
loading: boolean;
|
|
3
|
+
error: string | null;
|
|
4
|
+
success: boolean;
|
|
5
|
+
execute: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
|
|
6
|
+
reset: () => void;
|
|
7
|
+
};
|
|
8
|
+
export default useVerifyIdentity;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";var qt=Object.defineProperty;var Wt=(s,e,o)=>e in s?qt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[e]=o;var Ue=(s,e,o)=>Wt(s,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react"),gt=require("axios"),I=require("zod");var it={exports:{}},rt={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var yt;function Vt(){if(yt)return rt;yt=1;var s=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function o(n,i,d){var g=null;if(d!==void 0&&(g=""+d),i.key!==void 0&&(g=""+i.key),"key"in i){d={};for(var l in i)l!=="key"&&(d[l]=i[l])}else d=i;return i=d.ref,{$$typeof:s,type:n,key:g,ref:i!==void 0?i:null,props:d}}return rt.Fragment=e,rt.jsx=o,rt.jsxs=o,rt}var at={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var xt;function Gt(){return xt||(xt=1,process.env.NODE_ENV!=="production"&&(function(){function s(a){if(a==null)return null;if(typeof a=="function")return a.$$typeof===re?null:a.displayName||a.name||null;if(typeof a=="string")return a;switch(a){case L:return"Fragment";case P:return"Profiler";case V:return"StrictMode";case Q:return"Suspense";case le:return"SuspenseList";case ee:return"Activity"}if(typeof a=="object")switch(typeof a.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),a.$$typeof){case O:return"Portal";case T:return a.displayName||"Context";case G:return(a._context.displayName||"Context")+".Consumer";case A:var u=a.render;return a=a.displayName,a||(a=u.displayName||u.name||"",a=a!==""?"ForwardRef("+a+")":"ForwardRef"),a;case se:return u=a.displayName||null,u!==null?u:s(a.type)||"Memo";case M:u=a._payload,a=a._init;try{return s(a(u))}catch{}}return null}function e(a){return""+a}function o(a){try{e(a);var u=!1}catch{u=!0}if(u){u=console;var j=u.error,S=typeof Symbol=="function"&&Symbol.toStringTag&&a[Symbol.toStringTag]||a.constructor.name||"Object";return j.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",S),e(a)}}function n(a){if(a===L)return"<>";if(typeof a=="object"&&a!==null&&a.$$typeof===M)return"<...>";try{var u=s(a);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function i(){var a=J.A;return a===null?null:a.getOwner()}function d(){return Error("react-stack-top-frame")}function g(a){if(F.call(a,"key")){var u=Object.getOwnPropertyDescriptor(a,"key").get;if(u&&u.isReactWarning)return!1}return a.key!==void 0}function l(a,u){function j(){h||(h=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",u))}j.isReactWarning=!0,Object.defineProperty(a,"key",{get:j,configurable:!0})}function m(){var a=s(this.type);return p[a]||(p[a]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),a=this.props.ref,a!==void 0?a:null}function E(a,u,j,S,U,q){var z=j.ref;return a={$$typeof:v,type:a,key:u,props:j,_owner:S},(z!==void 0?z:null)!==null?Object.defineProperty(a,"ref",{enumerable:!1,get:m}):Object.defineProperty(a,"ref",{enumerable:!1,value:null}),a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(a,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(a,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.defineProperty(a,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a}function k(a,u,j,S,U,q){var z=u.children;if(z!==void 0)if(S)if(D(z)){for(S=0;S<z.length;S++)b(z[S]);Object.freeze&&Object.freeze(z)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else b(z);if(F.call(u,"key")){z=s(a);var W=Object.keys(u).filter(function(R){return R!=="key"});S=0<W.length?"{key: someKey, "+W.join(": ..., ")+": ...}":"{key: someKey}",w[z+S]||(W=0<W.length?"{"+W.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
|
+
let props = %s;
|
|
19
|
+
<%s {...props} />
|
|
20
|
+
React keys must be passed directly to JSX without using spread:
|
|
21
|
+
let props = %s;
|
|
22
|
+
<%s key={someKey} {...props} />`,S,z,W,z),w[z+S]=!0)}if(z=null,j!==void 0&&(o(j),z=""+j),g(u)&&(o(u.key),z=""+u.key),"key"in u){j={};for(var K in u)K!=="key"&&(j[K]=u[K])}else j=u;return z&&l(j,typeof a=="function"?a.displayName||a.name||"Unknown":a),E(a,z,j,i(),U,q)}function b(a){x(a)?a._store&&(a._store.validated=1):typeof a=="object"&&a!==null&&a.$$typeof===M&&(a._payload.status==="fulfilled"?x(a._payload.value)&&a._payload.value._store&&(a._payload.value._store.validated=1):a._store&&(a._store.validated=1))}function x(a){return typeof a=="object"&&a!==null&&a.$$typeof===v}var _=N,v=Symbol.for("react.transitional.element"),O=Symbol.for("react.portal"),L=Symbol.for("react.fragment"),V=Symbol.for("react.strict_mode"),P=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),T=Symbol.for("react.context"),A=Symbol.for("react.forward_ref"),Q=Symbol.for("react.suspense"),le=Symbol.for("react.suspense_list"),se=Symbol.for("react.memo"),M=Symbol.for("react.lazy"),ee=Symbol.for("react.activity"),re=Symbol.for("react.client.reference"),J=_.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F=Object.prototype.hasOwnProperty,D=Array.isArray,c=console.createTask?console.createTask:function(){return null};_={react_stack_bottom_frame:function(a){return a()}};var h,p={},f=_.react_stack_bottom_frame.bind(_,d)(),y=c(n(d)),w={};at.Fragment=L,at.jsx=function(a,u,j){var S=1e4>J.recentlyCreatedOwnerStacks++;return k(a,u,j,!1,S?Error("react-stack-top-frame"):f,S?c(n(a)):y)},at.jsxs=function(a,u,j){var S=1e4>J.recentlyCreatedOwnerStacks++;return k(a,u,j,!0,S?Error("react-stack-top-frame"):f,S?c(n(a)):y)}})()),at}var wt;function Kt(){return wt||(wt=1,process.env.NODE_ENV==="production"?it.exports=Vt():it.exports=Gt()),it.exports}var t=Kt();const mt=N.createContext(void 0);class ut{constructor(){Ue(this,"store",{})}getItem(e){return this.store[e]||null}setItem(e,o){this.store[e]=o}removeItem(e){delete this.store[e]}clear(){this.store={}}}class Ht{constructor(e){Ue(this,"adapter");this.adapter=this.resolveAdapter(e)}resolveAdapter(e){return!e||e==="localStorage"?typeof window<"u"?window.localStorage:new ut:e==="sessionStorage"?typeof window<"u"?window.sessionStorage:new ut:e==="memory"?new ut:e}async getItem(e){try{return await this.adapter.getItem(e)}catch(o){return console.error("StorageService: failed to get item",o),null}}async setItem(e,o){try{await this.adapter.setItem(e,o)}catch(n){console.error("StorageService: failed to set item",n)}}async removeItem(e){try{await this.adapter.removeItem(e)}catch(o){console.error("StorageService: failed to remove item",o)}}async clear(){try{await this.adapter.clear()}catch(e){console.error("StorageService: failed to clear",e)}}}function st(s){try{const e=s.split(".");if(e.length!==3)return null;const n=e[1].replace(/-/g,"+").replace(/_/g,"/"),i=decodeURIComponent(atob(n).split("").map(d=>"%"+("00"+d.charCodeAt(0).toString(16)).slice(-2)).join(""));return JSON.parse(i)}catch{return null}}function bt(s){if(!s)return!0;const e=st(s);return!e||!e.exp?!1:e.exp*1e3-1e4<Date.now()}function ie(s,e){if(!(!s||!e))return e.split(".").reduce((o,n)=>o?o[n]:void 0,s)}function ot(s,e){if(!e)return s;const o={};return Object.keys(s).forEach(n=>{const i=e[n]||n;o[i]=s[n]}),o}function Qe(s,e){return e?ie(s,e):ie(s,"accessToken")||ie(s,"Token")||ie(s,"token")||ie(s,"data.accessToken")||ie(s,"data.Token")||ie(s,"data.token")||null}function tt(s,e){return e?ie(s,e):ie(s,"refreshToken")||ie(s,"refresh_token")||ie(s,"RefreshToken")||ie(s,"data.refreshToken")||ie(s,"data.refresh_token")||ie(s,"data.RefreshToken")||null}function lt(s,e){return e?ie(s,e):ie(s,"user")||ie(s,"data.user")||(s&&(s.userId||s.id||s.email)?s:null)}class Yt{constructor(e){Ue(this,"storageService");this.storageService=e}async saveToken(e,o){await this.storageService.setItem(e,o)}async getToken(e){return this.storageService.getItem(e)}async removeToken(e){await this.storageService.removeItem(e)}decodeJWT(e){return st(e)}isExpired(e){return bt(e)}}class Jt{constructor(){Ue(this,"listeners",new Map)}on(e,o){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(o)}off(e,o){const n=this.listeners.get(e);n&&n.delete(o)}emit(e,o){const n=this.listeners.get(e);n&&n.forEach(i=>{try{i(o)}catch(d){console.error(`Error in event listener for ${e}:`,d)}})}}const ae=new Jt;let et=!1,pt=[];const vt=(s,e=null)=>{pt.forEach(o=>{s?o.reject(s):o.resolve(e)}),pt=[]};function Xt(s,e,o,n){const i=gt.create({baseURL:s.apiBaseUrl,withCredentials:!0});return i.interceptors.request.use(async d=>{s.headers&&Object.entries(s.headers).forEach(([m,E])=>{d.headers.set(m,E)});const g=s.tokenKey||"Token",l=await e.getToken(g);return l&&!d.headers.Authorization&&(d.headers.Authorization=`Bearer ${l}`),d},d=>Promise.reject(d)),i.interceptors.response.use(d=>d,async d=>{var l,m,E,k,b;const g=d.config;if(d.response&&d.response.status===401&&!g._retry&&s.enableRefreshToken!==!1){const x=((l=s.endpoints)==null?void 0:l.refreshToken)||"/refresh";if((m=g.url)!=null&&m.includes(x))return et=!1,n(),ae.emit("TOKEN_EXPIRED"),Promise.reject(d);if(et)return new Promise((L,V)=>{pt.push({resolve:P=>{g.headers.Authorization=`Bearer ${P}`,L(i(g))},reject:P=>{V(P)}})});g._retry=!0,et=!0;const _=s.tokenKey||"Token",v=s.refreshTokenKey||"refreshToken",O=await e.getToken(v);if(!O)return et=!1,n(),ae.emit("TOKEN_EXPIRED"),Promise.reject(d);try{const L=((E=s.endpoints)==null?void 0:E.refreshToken)||"/identity/access-token",V=L.includes("/identity/access-token"),P={...s.headers,...V?{refreshToken:O}:{}},G=await gt.post(`${s.apiBaseUrl}${L}`,V?null:{refreshToken:O},{headers:P,withCredentials:!0}),T=Qe(G.data,(k=s.responseMapping)==null?void 0:k.token),A=tt(G.data,(b=s.responseMapping)==null?void 0:b.refreshToken)||O;if(T)return await e.saveToken(_,T),A&&await e.saveToken(v,A),o(T,A),vt(null,T),g.headers.Authorization=`Bearer ${T}`,et=!1,i(g);throw new Error("Auth SDK: Token not returned in refresh response payload.")}catch(L){return et=!1,vt(L,null),n(),ae.emit("TOKEN_EXPIRED"),Promise.reject(L)}}return Promise.reject(d)}),i}class ze extends Error{constructor(o,n,i){super(o);Ue(this,"code");Ue(this,"originalError");this.name="AuthSdkError",this.code=n,this.originalError=i}}function Se(s){var e,o;if(s instanceof ze)return s;if(s!=null&&s.response){const n=s.response.status;let i=((e=s.response.data)==null?void 0:e.message)||((o=s.response.data)==null?void 0:o.error)||s.message||"";Array.isArray(i)?i=i.join(". "):typeof i=="object"&&i!==null&&(i=JSON.stringify(i));const d=typeof i=="string"?i.toLowerCase():"";return n===401?d.includes("otp")?new ze(i||"OTP verification expired or invalid.","OTP_EXPIRED",s):new ze(i||"Invalid credentials provided.","INVALID_CREDENTIALS",s):n===403?new ze(i||"Access token has expired or is invalid.","TOKEN_EXPIRED",s):n===404?new ze(i||"User or endpoint not found.","USER_NOT_FOUND",s):n>=500?new ze(i||"Internal server error occurred.","SERVER_ERROR",s):new ze(i||"API request failed.","UNKNOWN_ERROR",s)}return s!=null&&s.request?new ze("Network connection issue. Please check your connection.","NETWORK_ERROR",s):new ze((s==null?void 0:s.message)||"An unknown error occurred.","UNKNOWN_ERROR",s)}class Zt{constructor(e,o){Ue(this,"axiosInstance");Ue(this,"config");this.axiosInstance=e,this.config=o}getEndpoint(e,o){var n;return((n=this.config.endpoints)==null?void 0:n[e])||o}resolveUrl(e,o){if(!o)return e;let n=e;return Object.entries(o).forEach(([i,d])=>{n=n.replace(`:${i}`,String(d))}),n}async login(e){var o;try{const n={email:"email",password:"password",otp:"otp"},i=((o=this.config.requestMapping)==null?void 0:o.login)||n,d=ot({site:this.config.site,...e},i);if(d.otp!==void 0&&d.otp!==null){const m=Number(d.otp);isNaN(m)||(d.otp=m)}const g=this.getEndpoint("login","/identity/signin");return(await this.axiosInstance.post(g,d)).data}catch(n){throw Se(n)}}async signup(e){var o;try{const n={name:"fullName",email:"email",password:"password"},i=((o=this.config.requestMapping)==null?void 0:o.signup)||n,d=ot({site:this.config.site,...e},i),g=this.getEndpoint("signup","/identity/signup");return(await this.axiosInstance.post(g,d)).data}catch(n){throw Se(n)}}async verifyIdentity(e,o){var n;try{const i={email:"email"},d=((n=this.config.requestMapping)==null?void 0:n.verifyIdentity)||i,g=ot(e,d),l=this.getEndpoint("verifyIdentity","/identity/verify"),m=this.resolveUrl(l,o);if(m.includes("/identity/verify")){const k=this.config.site||sessionStorage.getItem("auth_registration_site")||"",b=g.email||g.Email;return(await this.axiosInstance.post(m,null,{params:{site:k,email:b}})).data}else return(await this.axiosInstance.post(m,g)).data}catch(i){throw Se(i)}}async verifyOtp(e,o){var n;try{const i=this.getEndpoint("verifyOtp","/identity/otp/validate"),d=this.resolveUrl(i,o);if(e.ResendOtp){const l=this.getEndpoint("verifyIdentity","/identity/verify"),m=e.Email||e.email||sessionStorage.getItem("auth_registration_email")||"",E=this.config.site||sessionStorage.getItem("auth_registration_site")||"";return(await this.axiosInstance.post(l,null,{params:{site:E,email:m}})).data}if(d.includes("/identity/otp/validate")){const l=e.Otp||e.otp,m=e.id||e.Id||sessionStorage.getItem("auth_registration_id")||"",k={site:e.site||e.Site||this.config.site||sessionStorage.getItem("auth_registration_site")||"",id:m,otp:typeof l=="string"?parseInt(l,10):l};return(await this.axiosInstance.post(d,k)).data}else{const l=ot(e,(n=this.config.requestMapping)==null?void 0:n.verifyOtp);return(await this.axiosInstance.post(d,l)).data}}catch(i){throw Se(i)}}async resetPassword(e,o){var n;try{const i={password:"password"},d=((n=this.config.requestMapping)==null?void 0:n.resetPassword)||i,g=ot(e,d),l=this.getEndpoint("resetPassword","/identity/update"),m=this.resolveUrl(l,o);if(m.includes("/identity/update")){const E=(o==null?void 0:o.site)||this.config.site||sessionStorage.getItem("auth_registration_site")||"",k=(o==null?void 0:o.id)||sessionStorage.getItem("auth_registration_id")||"",b=o==null?void 0:o.token;return(await this.axiosInstance.put(m,g,{params:{site:E,id:k},headers:b?{Authorization:`Bearer ${b}`}:void 0})).data}else{const E=o==null?void 0:o.token;return(await this.axiosInstance.post(m,g,{headers:E?{Authorization:`Bearer ${E}`}:void 0})).data}}catch(i){throw Se(i)}}async googleLogin(e){try{const o=this.getEndpoint("googleLogin","/identity/auth/google"),n=this.resolveUrl(o,{userId:e});return(await this.axiosInstance.get(n)).data}catch(o){throw Se(o)}}async logout(){try{const e=this.getEndpoint("logout","/logout");return(await this.axiosInstance.get(e)).data}catch(e){throw Se(e)}}async getUserProfile(e,o){try{const n=this.getEndpoint("getUser","/identity");return(await this.axiosInstance.get(n,{params:{site:e,id:o}})).data}catch(n){throw Se(n)}}async updateUser(e,o,n){try{const i=this.getEndpoint("updateUser","/identity/update");return(await this.axiosInstance.put(i,e,{params:{site:o,id:n}})).data}catch(i){throw Se(i)}}async deleteUser(e,o){try{const n=this.getEndpoint("deleteUser","/identity");return(await this.axiosInstance.delete(n,{params:{site:e,id:o}})).data}catch(n){throw Se(n)}}}const Qt=({children:s,config:e})=>{const[o,n]=N.useState(null),[i,d]=N.useState(null),[g,l]=N.useState(null),[m,E]=N.useState(!0),k=N.useMemo(()=>new Ht(e.storage),[e.storage]),b=N.useMemo(()=>new Yt(k),[k]),x=e.tokenKey||"Token",_=e.refreshTokenKey||"refreshToken",v=async(c,h=null,p=null)=>{if(n(c),c){await b.saveToken(x,c);const f=p||st(c)||null;l(f)}else await b.removeToken(x),l(null);h?(d(h),await b.saveToken(_,h)):c===null&&(d(null),await b.removeToken(_))},{axiosInstance:O,authApi:L}=N.useMemo(()=>{const c=Xt(e,b,(p,f)=>{n(p),f&&d(f)},()=>{n(null),d(null),l(null)}),h=new Zt(c,e);return{axiosInstance:c,authApi:h}},[e,b]);N.useEffect(()=>{(async()=>{var h,p,f;try{const y=await b.getToken(x),w=await b.getToken(_);if(y)if(b.isExpired(y))if(e.autoRefresh!==!1&&w)try{let a;if(e.isExternalApiCall&&e.onRefresh)a=await e.onRefresh(w);else{const S=((h=e.endpoints)==null?void 0:h.refreshToken)||"/identity/access-token",U=S.includes("/identity/access-token");a=(await O.post(S,U?null:{refreshToken:w},{headers:U?{refreshToken:w}:{}})).data}const u=Qe(a,(p=e.responseMapping)==null?void 0:p.token),j=tt(a,(f=e.responseMapping)==null?void 0:f.refreshToken)||w;u?await v(u,j):await v(null)}catch{await v(null)}else await v(null);else await v(y,w)}catch(y){console.error("Auth SDK Provider: session recovery failed.",y)}finally{E(!1)}})()},[]);const V=()=>o?st(o):null,P=async c=>{var h,p,f,y,w,a;try{const u=e.isExternalApiCall&&e.onLogin?await e.onLogin(c):await L.login(c);if(u&&(u.error||u.success===!1))throw new Error(u.error||u.message||"Login failed.");const j=Qe(u,(h=e.responseMapping)==null?void 0:h.token),S=tt(u,(p=e.responseMapping)==null?void 0:p.refreshToken),U=lt(u,(f=e.responseMapping)==null?void 0:f.user);return j?(await v(j,S,U),ae.emit("LOGIN_SUCCESS",{user:U||st(j),token:j})):l(U||null),u}catch(u){if(u&&(u.message==="Email not verified"||((a=(w=(y=u.originalError)==null?void 0:y.response)==null?void 0:w.data)==null?void 0:a.message)==="Email not verified")){const S=c.email||c.Email;if(S){sessionStorage.setItem("auth_registration_email",S);try{await A({email:S})}catch(U){console.error("Failed to trigger OTP email dispatch:",U)}}ae.emit("OTP_SENT",{email:S})}throw ae.emit("LOGIN_FAILED",u),u}},G=async c=>{var h,p,f;try{const y=e.isExternalApiCall&&e.onSignup?await e.onSignup(c):await L.signup(c);if(y&&(y.error||y.success===!1))throw new Error(y.error||y.message||"Registration failed.");if(y&&y.id){sessionStorage.setItem("auth_registration_id",y.id),sessionStorage.setItem("auth_registration_site",y.site||e.site||"");const j=c.Email||c.email;j&&sessionStorage.setItem("auth_registration_email",j)}y&&y.isOtpSent&&y.isVerified===!1&&ae.emit("OTP_SENT",y);const w=Qe(y,(h=e.responseMapping)==null?void 0:h.token),a=tt(y,(p=e.responseMapping)==null?void 0:p.refreshToken),u=lt(y,(f=e.responseMapping)==null?void 0:f.user);return w?await v(w,a,u):l(u||null),y}catch(y){throw y}},T=async(c,h)=>{var p,f,y;try{const w=e.isExternalApiCall&&e.onVerifyOtp?await e.onVerifyOtp(c,h):await L.verifyOtp(c,h);if(w&&(w.error||w.success===!1))throw new Error(w.error||w.message||"OTP verification failed.");const a=Qe(w,(p=e.responseMapping)==null?void 0:p.token),u=tt(w,(f=e.responseMapping)==null?void 0:f.refreshToken),j=lt(w,(y=e.responseMapping)==null?void 0:y.user),S=c.isResetPassword===!0||sessionStorage.getItem("auth_reset_flow")==="true";return a&&!S&&await v(a,u,j),c.ResendOtp||ae.emit("OTP_VERIFIED",w),w}catch(w){throw w}},A=async(c,h)=>{try{const p=e.isExternalApiCall&&e.onVerifyIdentity?await e.onVerifyIdentity(c,h):await L.verifyIdentity(c,h);if(p&&(p.error||p.success===!1))throw new Error(p.error||p.message||"Identity verification request failed.");if(sessionStorage.setItem("auth_reset_flow","true"),p&&p.id){sessionStorage.setItem("auth_registration_id",p.id),sessionStorage.setItem("auth_registration_site",p.site||e.site||"");const f=c.Email||c.email;f&&sessionStorage.setItem("auth_registration_email",f)}return p}catch(p){throw p}},Q=async(c,h)=>{var p,f,y;try{const w=e.isExternalApiCall&&e.onResetPassword?await e.onResetPassword(c,h):await L.resetPassword(c,h);if(w&&(w.error||w.success===!1))throw new Error(w.error||w.message||"Password reset failed.");const a=Qe(w,(p=e.responseMapping)==null?void 0:p.token),u=tt(w,(f=e.responseMapping)==null?void 0:f.refreshToken),j=lt(w,(y=e.responseMapping)==null?void 0:y.user);return a&&await v(a,u,j),sessionStorage.removeItem("auth_reset_flow"),ae.emit("PASSWORD_RESET",w),w}catch(w){throw w}},le=async()=>{var f,y;const c=await b.getToken(_);if(!c)throw new Error("Auth SDK: No refresh token is cached.");let h;if(e.isExternalApiCall&&e.onRefresh)h=await e.onRefresh(c);else{const w=((f=e.endpoints)==null?void 0:f.refreshToken)||"/identity/access-token",a=w.includes("/identity/access-token");h=(await O.post(w,a?null:{refreshToken:c},{headers:a?{refreshToken:c}:{}})).data}const p=Qe(h,(y=e.responseMapping)==null?void 0:y.token);return p?(await v(p),p):null},se=async(c,h)=>{try{const p=V(),f=c||(p==null?void 0:p.site)||e.site||"",y=h||(p==null?void 0:p.userId)||"";return e.isExternalApiCall&&e.onGetUser?await e.onGetUser(f,y):await L.getUserProfile(f,y)}catch(p){throw p}},M=async(c,h,p)=>{try{const f=V(),y=h||(f==null?void 0:f.site)||e.site||"",w=p||(f==null?void 0:f.userId)||"",a=e.isExternalApiCall&&e.onUpdateUser?await e.onUpdateUser(c,y,w):await L.updateUser(c,y,w);if(a&&(a.error||a.success===!1))throw new Error(a.error||a.message||"Profile update failed.");return a&&l(u=>({...u,...a})),a}catch(f){throw f}},ee=async(c,h)=>{try{const p=V(),f=c||(p==null?void 0:p.site)||e.site||"",y=h||(p==null?void 0:p.userId)||"",w=e.isExternalApiCall&&e.onDeleteUser?await e.onDeleteUser(f,y):await L.deleteUser(f,y);return await v(null),ae.emit("LOGOUT"),w}catch(p){throw p}},re=async()=>{try{e.isExternalApiCall&&e.onLogout?await e.onLogout():await L.logout()}catch{}finally{await v(null),ae.emit("LOGOUT")}},J=!!o,F=N.useMemo(()=>{var te,H;const c={},h=e.theme;let p="#3f51b5",f="#303f9f",y="#ff4081",w="#f4f6f8",a="#ffffff",u="#1a1f36",j="#5c7080",S="#e1e8ed",U="#d32f2f",q="#2e7d32",z="8px",W="8px",K="8px",R="8px",B="16px",$="system-ui, -apple-system, sans-serif",X="system-ui, -apple-system, sans-serif",Y="linear-gradient(135deg, #e0e8f5 0%, #f4f6f8 100%)";if(h==="dark")p="#6366f1",f="#4f46e5",y="#ec4899",w="#0f172a",a="#1e293b",u="#f8fafc",j="#94a3b8",S="#334155",U="#f87171",q="#4ade80",z="8px",W="16px",K="8px",R="8px",Y="linear-gradient(135deg, #090d16 0%, #0f172a 100%)";else if(h&&typeof h=="object"){const C=h.colors||{};C.primary&&(p=C.primary),C.primaryHover&&(f=C.primaryHover),C.secondary&&(y=C.secondary),C.background&&(w=C.background),C.surface&&(a=C.surface),C.text&&(u=C.text),C.textMuted&&(j=C.textMuted),C.border&&(S=C.border),C.error&&(U=C.error),C.success&&(q=C.success),(te=h.fonts)!=null&&te.body&&($=h.fonts.body),(H=h.fonts)!=null&&H.heading&&(X=h.fonts.heading),h.borderRadius&&(z=h.borderRadius,W=h.borderRadius,K=h.borderRadius,R=h.borderRadius),h.borderRadiusCard&&(W=h.borderRadiusCard),h.borderRadiusButton&&(K=h.borderRadiusButton),h.borderRadiusInput&&(R=h.borderRadiusInput),h.spacing&&(B=h.spacing),h.background&&(Y=h.background)}return c["--auth-color-primary"]=p,c["--auth-color-primary-hover"]=f,c["--auth-color-secondary"]=y,c["--auth-color-background"]=w,c["--auth-color-surface"]=a,c["--auth-color-text"]=u,c["--auth-color-text-muted"]=j,c["--auth-color-border"]=S,c["--auth-color-error"]=U,c["--auth-color-success"]=q,c["--auth-font-body"]=$,c["--auth-font-heading"]=X,c["--auth-border-radius"]=z,c["--auth-border-radius-card"]=W,c["--auth-border-radius-button"]=K,c["--auth-border-radius-input"]=R,c["--auth-spacing"]=B,c["--auth-bg-style"]=Y,c},[e.theme]),D=N.useMemo(()=>({user:g,token:o,refreshToken:i,isAuthenticated:J,loading:m,login:P,logout:re,signup:G,verifyOtp:T,verifyIdentity:A,resetPassword:Q,refresh:le,getUserProfile:se,updateUser:M,deleteUser:ee,config:e,authApi:L}),[g,o,i,J,m,e,L]);return t.jsx(mt.Provider,{value:D,children:t.jsx("div",{style:F,className:"auth-sdk-provider-container",children:s})})};function pe(){const s=N.useContext(mt);if(!s)throw new Error("useAuth must be used within an AuthProvider");return s}function jt(){const{login:s}=pe(),[e,o]=N.useState(!1),[n,i]=N.useState(null),[d,g]=N.useState(!1);return{loading:e,error:n,success:d,execute:async E=>{o(!0),i(null),g(!1);try{const k=await s(E);return g(!0),k}catch(k){throw i((k==null?void 0:k.message)||"Login failed."),k}finally{o(!1)}},reset:()=>{i(null),g(!1)}}}function Et(){const{signup:s}=pe(),[e,o]=N.useState(!1),[n,i]=N.useState(null),[d,g]=N.useState(!1);return{loading:e,error:n,success:d,execute:async E=>{o(!0),i(null),g(!1);try{const k=await s(E);return g(!0),k}catch(k){throw i((k==null?void 0:k.message)||"Registration failed."),k}finally{o(!1)}},reset:()=>{i(null),g(!1)}}}function kt(){const{verifyIdentity:s}=pe(),[e,o]=N.useState(!1),[n,i]=N.useState(null),[d,g]=N.useState(!1);return{loading:e,error:n,success:d,execute:async(E,k)=>{o(!0),i(null),g(!1);try{const b=await s(E,k);return g(!0),b}catch(b){throw i((b==null?void 0:b.message)||"Failed to submit identity verification request."),b}finally{o(!1)}},reset:()=>{i(null),g(!1)}}}function Nt(){const{verifyOtp:s}=pe(),[e,o]=N.useState(!1),[n,i]=N.useState(null),[d,g]=N.useState(!1);return{loading:e,error:n,success:d,execute:async(k,b)=>{o(!0),i(null),g(!1);try{const x=await s(k,b);return g(!0),x}catch(x){throw i((x==null?void 0:x.message)||"OTP verification failed."),x}finally{o(!1)}},resend:async(k,b)=>{o(!0),i(null);try{return await s(k,b)}catch(x){throw i((x==null?void 0:x.message)||"Failed to resend OTP."),x}finally{o(!1)}},reset:()=>{i(null),g(!1)}}}function St(){const{resetPassword:s}=pe(),[e,o]=N.useState(!1),[n,i]=N.useState(null),[d,g]=N.useState(!1);return{loading:e,error:n,success:d,execute:async(E,k)=>{o(!0),i(null),g(!1);try{const b=await s(E,k);return g(!0),b}catch(b){throw i((b==null?void 0:b.message)||"Password reset failed."),b}finally{o(!1)}},reset:()=>{i(null),g(!1)}}}function Tt(){const{updateUser:s}=pe(),[e,o]=N.useState(!1),[n,i]=N.useState(null),[d,g]=N.useState(!1);return{loading:e,error:n,success:d,execute:async(E,k,b)=>{o(!0),i(null),g(!1);try{const x=await s(E,k,b);return g(!0),x}catch(x){throw i((x==null?void 0:x.message)||"Profile update failed."),x}finally{o(!1)}},reset:()=>{i(null),g(!1)}}}const es="_card_1gys8_2",ts="_heading_1gys8_18",ss="_subtext_1gys8_30",rs="_form_1gys8_39",as="_formGroup_1gys8_45",os="_label_1gys8_52",ns="_inputWrapper_1gys8_59",is="_input_1gys8_59",ls="_inputError_1gys8_89",cs="_inputIcon_1gys8_98",ds="_eyeIcon_1gys8_116",us="_errorText_1gys8_121",ps="_button_1gys8_131",ms="_link_1gys8_160",hs="_footerText_1gys8_177",fs="_divider_1gys8_185",gs="_googleButton_1gys8_211",ys="_googleIcon_1gys8_233",xs="_apiErrorBlock_1gys8_267",ws="_apiErrorIcon_1gys8_285",vs="_apiSuccessBlock_1gys8_294",bs="_apiSuccessIcon_1gys8_312",r={card:es,heading:ts,subtext:ss,form:rs,formGroup:as,label:os,inputWrapper:ns,input:is,inputError:ls,inputIcon:cs,eyeIcon:ds,errorText:us,button:ps,link:ms,footerText:hs,divider:fs,googleButton:gs,googleIcon:ys,apiErrorBlock:xs,apiErrorIcon:ws,apiSuccessBlock:vs,apiSuccessIcon:bs},ht=({buttonText:s,className:e})=>{var d,g;const{config:o}=pe(),n=()=>{var E;const l=((E=o.endpoints)==null?void 0:E.googleLogin)||"/auth/google",m=l.startsWith("http")?l:`${o.apiBaseUrl}${l}`;window.open(m,"_self")},i=s||((g=(d=o.customization)==null?void 0:d.buttonText)==null?void 0:g.google)||"Sign in with Google";return t.jsxs("button",{type:"button",onClick:n,className:`${r.googleButton} ${e||""}`,"aria-label":i,children:[t.jsxs("svg",{className:r.googleIcon,viewBox:"0 0 24 24","aria-hidden":"true",children:[t.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),t.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),t.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.06H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.94l2.85-2.22.81-.63z"}),t.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.06l3.66 2.84c.87-2.6 3.3-4.52 6.16-4.52z"})]}),t.jsx("span",{children:i})]})},Re=({message:s,type:e,style:o,onDismiss:n})=>{const[i,d]=N.useState(s);return N.useEffect(()=>{d(s)},[s]),N.useEffect(()=>{if(i){const g=setTimeout(()=>{d(null),n&&n()},3e3);return()=>clearTimeout(g)}},[i,n]),i?e==="success"?t.jsxs("div",{className:r.apiSuccessBlock,style:o,role:"status",children:[t.jsx("svg",{className:r.apiSuccessIcon,viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),t.jsx("span",{children:i})]}):t.jsxs("div",{className:r.apiErrorBlock,style:o,role:"alert",children:[t.jsx("svg",{className:r.apiErrorIcon,viewBox:"0 0 20 20",fill:"currentColor",children:t.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})}),t.jsx("span",{children:i})]}):null},_t=I.z.object({email:I.z.string().email("Please enter a valid email address"),password:I.z.string().min(1,"Password is required")}),Pt=I.z.object({email:I.z.string().email("Please enter a valid email address")}),It=I.z.object({email:I.z.string().email("Please enter a valid email address"),otp:I.z.string().min(1,"OTP is required")}),zt=I.z.object({name:I.z.string().min(1,"Name is required"),email:I.z.string().email("Please enter a valid email address"),password:I.z.string().min(6,"Password must be at least 6 characters long"),verifyPassword:I.z.string().min(1,"Please confirm your password")}).refine(s=>s.password===s.verifyPassword,{message:"Passwords do not match",path:["verifyPassword"]}),Rt=I.z.object({email:I.z.string().email("Please enter a valid email address")}),Lt=I.z.object({otp:I.z.string().min(4,"OTP must be at least 4 digits").max(8,"OTP is too long")}),Ot=I.z.object({password:I.z.string().min(6,"Password must be at least 6 characters long"),verifyPassword:I.z.string().min(1,"Please confirm your password")}).refine(s=>s.password===s.verifyPassword,{message:"Passwords do not match",path:["verifyPassword"]}),Ct=I.z.object({fullName:I.z.string().min(1,"Full name is required").optional().or(I.z.literal("")),email:I.z.string().email("Please enter a valid email address").optional().or(I.z.literal("")),username:I.z.string().optional(),phoneNumber:I.z.string().optional(),password:I.z.string().min(6,"Password must be at least 6 characters long").optional().or(I.z.literal("")),profileUrl:I.z.string().url("Please enter a valid URL").optional().or(I.z.literal("")),city:I.z.string().optional(),state:I.z.string().optional(),country:I.z.string().optional(),postalcode:I.z.string().optional(),timezone:I.z.string().optional()}),At=({components:s,labels:e,buttonText:o,placeholders:n,validationSchema:i,onSuccess:d,onForgotPasswordClick:g,onSignupClick:l})=>{var Y,te,H,C,ce,fe,me,oe,je,ge,Te,we,_e,ye,xe,he,ve,Pe,Me,Fe,$e,De,Be,qe,We,Ve,Ge,Ke,He,Ye,Je,Xe,Le,Oe,Ee,ue,ke,Ce,de,Ie,nt,Ze;const{config:m,verifyIdentity:E}=pe(),{loading:k,error:b,execute:x,reset:_}=jt(),[v,O]=N.useState({}),[L,V]=N.useState(!0),[P,G]=N.useState(null),[T,A]=N.useState("password"),[Q,le]=N.useState(""),[se,M]=N.useState(""),[ee,re]=N.useState(!1),[J,F]=N.useState(!1),[D,c]=N.useState(null),h=i||((te=(Y=m.customization)==null?void 0:Y.validationSchema)==null?void 0:te.login)||_t,p=async ne=>{ne.preventDefault(),O({}),c(null),G(null);try{Pt.parse({email:Q})}catch(Z){if(Z instanceof I.z.ZodError){O({[R]:Z.errors[0].message});return}}F(!0);try{await E({[R]:Q}),re(!0),c("OTP has been sent to your e-mail.")}catch(Z){G(Z.message||"Failed to send OTP.")}finally{F(!1)}},f=async ne=>{if(ne.preventDefault(),O({}),c(null),G(null),T==="otp"){if(!ee)return;try{It.parse({email:Q,otp:se})}catch(Z){if(Z instanceof I.z.ZodError){const be={};Z.errors.forEach(Ae=>{if(Ae.path[0]){const Ne=Ae.path[0].toString()==="email"?R:Ae.path[0].toString()==="otp"?$:Ae.path[0].toString();be[Ne]=Ae.message}}),O(be);return}}try{const Z=await x({[R]:Q,[$]:se});d&&d(Z)}catch(Z){G((Z==null?void 0:Z.message)||"Verification failed.")}}else{const Z=new FormData(ne.currentTarget),be=Object.fromEntries(Z.entries()),Ae={email:be[R],password:be[B]};try{h.parse(Ae)}catch(Ne){if(Ne instanceof I.z.ZodError){const ft={};Ne.errors.forEach(ct=>{if(ct.path[0]){const dt=ct.path[0].toString(),Bt=dt==="email"?R:dt==="password"?B:dt;ft[Bt]=ct.message}}),O(ft);return}}try{const Ne=await x(be);d&&d(Ne)}catch(Ne){G((Ne==null?void 0:Ne.message)||"Login failed."),console.error("[SDK Login Component] Error caught during form submit:",Ne)}}},y=(s==null?void 0:s.Card)||"div",w=(s==null?void 0:s.Button)||"button",a=s==null?void 0:s.Input,u=((C=(H=m.customization)==null?void 0:H.labels)==null?void 0:C.loginTitle)||"Log In",j=(e==null?void 0:e.email)||((fe=(ce=m.customization)==null?void 0:ce.labels)==null?void 0:fe.loginEmail)||((oe=(me=m.customization)==null?void 0:me.labels)==null?void 0:oe.email)||"E-mail",S=(e==null?void 0:e.password)||((ge=(je=m.customization)==null?void 0:je.labels)==null?void 0:ge.loginPassword)||((we=(Te=m.customization)==null?void 0:Te.labels)==null?void 0:we.password)||"Password",U=o||((ye=(_e=m.customization)==null?void 0:_e.buttonText)==null?void 0:ye.login)||"Login",q=(n==null?void 0:n.email)||((he=(xe=m.customization)==null?void 0:xe.placeholders)==null?void 0:he.loginEmail)||((Pe=(ve=m.customization)==null?void 0:ve.placeholders)==null?void 0:Pe.email)||"E-mail",z=(n==null?void 0:n.password)||((Fe=(Me=m.customization)==null?void 0:Me.placeholders)==null?void 0:Fe.loginPassword)||((De=($e=m.customization)==null?void 0:$e.placeholders)==null?void 0:De.password)||"Password",W=((qe=(Be=m.customization)==null?void 0:Be.labels)==null?void 0:qe.otpLabel)||"OTP Code",K=((Ve=(We=m.customization)==null?void 0:We.placeholders)==null?void 0:Ve.otpPlaceholder)||"123456",R=((Ke=(Ge=m.requestMapping)==null?void 0:Ge.login)==null?void 0:Ke.email)||"email",B=((Ye=(He=m.requestMapping)==null?void 0:He.login)==null?void 0:Ye.password)||"password",$=((Xe=(Je=m.requestMapping)==null?void 0:Je.login)==null?void 0:Xe.otp)||((Oe=(Le=m.requestMapping)==null?void 0:Le.otp)==null?void 0:Oe.otp)||"otp",X=k||J;return t.jsxs(y,{className:r.card,children:[t.jsx("h1",{className:r.heading,children:u}),t.jsxs("form",{onSubmit:f,className:r.form,noValidate:!0,children:[t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:R,className:r.label,children:j}),t.jsx("div",{className:r.inputWrapper,children:a?t.jsx(a,{type:"email",id:R,name:R,value:Q,onChange:ne=>le(ne.target.value),placeholder:q,error:v[R],disabled:ee&&T==="otp"}):t.jsx("input",{type:"email",id:R,name:R,value:Q,onChange:ne=>le(ne.target.value),placeholder:q,className:`${r.input} ${v[R]?r.inputError:""}`,required:!0,disabled:ee&&T==="otp","aria-invalid":!!v[R],"aria-describedby":v[R]?`${R}-error`:void 0})}),v[R]&&t.jsx("span",{id:`${R}-error`,className:r.errorText,role:"alert",children:v[R]})]}),T==="otp"?ee&&t.jsxs("div",{className:r.formGroup,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{htmlFor:$,className:r.label,children:W}),t.jsx("button",{type:"button",onClick:p,className:r.link,style:{fontSize:"0.75rem",background:"none",border:"none",padding:0},children:"Resend OTP"})]}),t.jsx("div",{className:r.inputWrapper,children:a?t.jsx(a,{type:"text",id:$,name:$,value:se,onChange:ne=>M(ne.target.value),placeholder:K,error:v[$]}):t.jsx("input",{type:"text",id:$,name:$,value:se,onChange:ne=>M(ne.target.value),placeholder:K,className:`${r.input} ${v[$]?r.inputError:""}`,required:!0,"aria-invalid":!!v[$],"aria-describedby":v[$]?`${$}-error`:void 0})}),v[$]&&t.jsx("span",{id:`${$}-error`,className:r.errorText,role:"alert",children:v[$]})]}):t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:B,className:r.label,children:S}),t.jsx("div",{className:r.inputWrapper,children:a?t.jsx(a,{type:L?"password":"text",id:B,name:B,placeholder:z,error:v[B]}):t.jsxs(t.Fragment,{children:[t.jsx("input",{type:L?"password":"text",id:B,name:B,placeholder:z,className:`${r.input} ${v[B]?r.inputError:""}`,required:!0,"aria-invalid":!!v[B],"aria-describedby":v[B]?`${B}-error`:void 0}),t.jsx("button",{type:"button",onClick:()=>V(!L),className:r.inputIcon,"aria-label":L?"Show password":"Hide password",children:L?t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}):t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})})]})}),v[B]&&t.jsx("span",{id:`${B}-error`,className:r.errorText,role:"alert",children:v[B]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"-4px"},children:[m.enableOtpLogin&&t.jsx("button",{type:"button",onClick:()=>{A(T==="password"?"otp":"password"),O({}),c(null),G(null),_()},className:r.link,style:{background:"none",border:"none",padding:0},children:T==="password"?"Login with OTP":"Login with Password"}),T==="password"&&g&&t.jsx("button",{type:"button",onClick:g,className:r.link,children:((ue=(Ee=m.customization)==null?void 0:Ee.labels)==null?void 0:ue.loginForgotPasswordLink)||"Forgot password?"})]}),t.jsx(Re,{message:D,type:"success",style:{marginTop:"8px",marginBottom:"8px"},onDismiss:()=>c(null)}),t.jsx(Re,{message:P||b,type:"error",style:{marginTop:"8px",marginBottom:"8px"},onDismiss:()=>{G(null),_()}}),T==="otp"&&!ee?t.jsx(w,{type:"button",onClick:p,disabled:X,className:r.button,children:X?"Sending OTP...":"Send OTP"}):t.jsx(w,{type:"submit",disabled:X,className:r.button,children:X?s!=null&&s.Loader?t.jsx(s.Loader,{}):"Loading...":U}),l&&t.jsxs("div",{className:r.footerText,children:[((Ce=(ke=m.customization)==null?void 0:ke.labels)==null?void 0:Ce.loginDontHaveAccountText)||"Don't have an account? "," ",t.jsx("button",{type:"button",onClick:l,className:r.link,style:{background:"none",border:"none",padding:0},children:((Ie=(de=m.customization)==null?void 0:de.labels)==null?void 0:Ie.loginSignupLink)||"SignUp"})]}),m.enableGoogleLogin!==!1&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:r.divider,children:((Ze=(nt=m.customization)==null?void 0:nt.labels)==null?void 0:Ze.loginDividerText)||"or"}),t.jsx(ht,{})]})]})]})},Ut=({components:s,labels:e,buttonText:o,placeholders:n,validationSchema:i,onSuccess:d,onLoginClick:g})=>{var y,w,a,u,j,S,U,q,z,W,K,R,B,$,X,Y,te,H,C,ce,fe,me,oe,je,ge,Te,we,_e,ye,xe,he,ve,Pe,Me,Fe,$e,De,Be,qe,We,Ve,Ge,Ke,He,Ye,Je,Xe,Le,Oe,Ee,ue,ke;const{config:l}=pe(),{loading:m,error:E,execute:k,reset:b}=Et(),[x,_]=N.useState({}),[v,O]=N.useState({pass:!0,verify:!0}),L=i||((w=(y=l.customization)==null?void 0:y.validationSchema)==null?void 0:w.signup)||zt,V=async Ce=>{Ce.preventDefault(),_({});const de=new FormData(Ce.currentTarget),Ie=Object.fromEntries(de.entries()),nt={name:Ie[c],email:Ie[h],password:Ie[p],verifyPassword:Ie[f]};try{L.parse(nt)}catch(Ze){if(Ze instanceof I.z.ZodError){const ne={};Ze.errors.forEach(Z=>{if(Z.path[0]){const be=Z.path[0].toString(),Ae=be==="name"?c:be==="email"?h:be==="password"?p:be==="verifyPassword"?f:be;ne[Ae]=Z.message}}),_(ne);return}}try{const{[f]:Ze,...ne}=Ie,Z=await k(ne);d&&d(Z)}catch{}},P=(s==null?void 0:s.Card)||"div",G=(s==null?void 0:s.Button)||"button",T=s==null?void 0:s.Input,A=((u=(a=l.customization)==null?void 0:a.labels)==null?void 0:u.signupTitle)||"Sign Up",Q=(e==null?void 0:e.name)||((S=(j=l.customization)==null?void 0:j.labels)==null?void 0:S.signupName)||((q=(U=l.customization)==null?void 0:U.labels)==null?void 0:q.name)||"Name",le=(e==null?void 0:e.email)||((W=(z=l.customization)==null?void 0:z.labels)==null?void 0:W.signupEmail)||((R=(K=l.customization)==null?void 0:K.labels)==null?void 0:R.email)||"E-mail",se=(e==null?void 0:e.password)||(($=(B=l.customization)==null?void 0:B.labels)==null?void 0:$.signupPassword)||((Y=(X=l.customization)==null?void 0:X.labels)==null?void 0:Y.password)||"Password",M=(e==null?void 0:e.verifyPassword)||((H=(te=l.customization)==null?void 0:te.labels)==null?void 0:H.signupVerifyPassword)||((ce=(C=l.customization)==null?void 0:C.labels)==null?void 0:ce.verifyPassword)||"Verify Password",ee=o||((me=(fe=l.customization)==null?void 0:fe.buttonText)==null?void 0:me.signup)||"Register",re=(n==null?void 0:n.name)||((je=(oe=l.customization)==null?void 0:oe.placeholders)==null?void 0:je.signupName)||((Te=(ge=l.customization)==null?void 0:ge.placeholders)==null?void 0:Te.name)||"Name",J=(n==null?void 0:n.email)||((_e=(we=l.customization)==null?void 0:we.placeholders)==null?void 0:_e.signupEmail)||((xe=(ye=l.customization)==null?void 0:ye.placeholders)==null?void 0:xe.email)||"E-mail",F=(n==null?void 0:n.password)||((ve=(he=l.customization)==null?void 0:he.placeholders)==null?void 0:ve.signupPassword)||((Me=(Pe=l.customization)==null?void 0:Pe.placeholders)==null?void 0:Me.password)||"Password",D=(n==null?void 0:n.verifyPassword)||(($e=(Fe=l.customization)==null?void 0:Fe.placeholders)==null?void 0:$e.signupVerifyPassword)||((Be=(De=l.customization)==null?void 0:De.placeholders)==null?void 0:Be.verifyPassword)||"Verify Password",c=((We=(qe=l.requestMapping)==null?void 0:qe.signup)==null?void 0:We.name)||"name",h=((Ge=(Ve=l.requestMapping)==null?void 0:Ve.signup)==null?void 0:Ge.email)||"email",p=((He=(Ke=l.requestMapping)==null?void 0:Ke.signup)==null?void 0:He.password)||"password",f=((Je=(Ye=l.requestMapping)==null?void 0:Ye.signup)==null?void 0:Je.verifyPassword)||"verifyPassword";return t.jsxs(P,{className:r.card,children:[t.jsx("h1",{className:r.heading,children:A}),t.jsxs("form",{onSubmit:V,className:r.form,noValidate:!0,children:[t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:c,className:r.label,children:Q}),t.jsx("div",{className:r.inputWrapper,children:T?t.jsx(T,{type:"text",id:c,name:c,placeholder:re,error:x[c]}):t.jsx("input",{type:"text",id:c,name:c,placeholder:re,className:`${r.input} ${x[c]?r.inputError:""}`,required:!0,"aria-invalid":!!x[c],"aria-describedby":x[c]?`${c}-error`:void 0})}),x[c]&&t.jsx("span",{id:`${c}-error`,className:r.errorText,role:"alert",children:x[c]})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:h,className:r.label,children:le}),t.jsx("div",{className:r.inputWrapper,children:T?t.jsx(T,{type:"email",id:h,name:h,placeholder:J,error:x[h]}):t.jsx("input",{type:"email",id:h,name:h,placeholder:J,className:`${r.input} ${x[h]?r.inputError:""}`,required:!0,"aria-invalid":!!x[h],"aria-describedby":x[h]?`${h}-error`:void 0})}),x[h]&&t.jsx("span",{id:`${h}-error`,className:r.errorText,role:"alert",children:x[h]})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:p,className:r.label,children:se}),t.jsx("div",{className:r.inputWrapper,children:T?t.jsx(T,{type:v.pass?"password":"text",id:p,name:p,placeholder:F,error:x[p]}):t.jsxs(t.Fragment,{children:[t.jsx("input",{type:v.pass?"password":"text",id:p,name:p,placeholder:F,className:`${r.input} ${x[p]?r.inputError:""}`,required:!0,"aria-invalid":!!x[p],"aria-describedby":x[p]?`${p}-error`:void 0}),t.jsx("button",{type:"button",onClick:()=>O({...v,pass:!v.pass}),className:r.inputIcon,"aria-label":v.pass?"Show password":"Hide password",children:v.pass?t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}):t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})})]})}),x[p]&&t.jsx("span",{id:`${p}-error`,className:r.errorText,role:"alert",children:x[p]})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:f,className:r.label,children:M}),t.jsx("div",{className:r.inputWrapper,children:T?t.jsx(T,{type:v.verify?"password":"text",id:f,name:f,placeholder:D,error:x[f]}):t.jsxs(t.Fragment,{children:[t.jsx("input",{type:v.verify?"password":"text",id:f,name:f,placeholder:D,className:`${r.input} ${x[f]?r.inputError:""}`,required:!0,"aria-invalid":!!x[f],"aria-describedby":x[f]?`${f}-error`:void 0}),t.jsx("button",{type:"button",onClick:()=>O({...v,verify:!v.verify}),className:r.inputIcon,"aria-label":v.verify?"Show password":"Hide password",children:v.verify?t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}):t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})})]})}),x[f]&&t.jsx("span",{id:`${f}-error`,className:r.errorText,role:"alert",children:x[f]})]}),t.jsx(Re,{message:E,type:"error",style:{marginTop:"8px",marginBottom:"8px"},onDismiss:b}),t.jsx(G,{type:"submit",disabled:m,className:r.button,children:m?s!=null&&s.Loader?t.jsx(s.Loader,{}):"Loading...":ee}),g&&t.jsxs("div",{className:r.footerText,children:[((Le=(Xe=l.customization)==null?void 0:Xe.labels)==null?void 0:Le.signupAlreadyHaveAccountText)||"Already have an account? "," ",t.jsx("button",{type:"button",onClick:g,className:r.link,style:{background:"none",border:"none",padding:0},children:((Ee=(Oe=l.customization)==null?void 0:Oe.labels)==null?void 0:Ee.signupLoginLink)||"Login"})]}),l.enableGoogleLogin!==!1&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:r.divider,children:((ke=(ue=l.customization)==null?void 0:ue.labels)==null?void 0:ke.signupDividerText)||"or"}),t.jsx(ht,{})]})]})]})},Mt=({components:s,labels:e,buttonText:o,placeholders:n,validationSchema:i,onSuccess:d,onBackToLoginClick:g})=>{var ee,re,J,F,D,c,h,p,f,y,w,a,u,j,S,U,q,z,W,K;const{config:l}=pe(),{loading:m,error:E,success:k,execute:b,reset:x}=kt(),[_,v]=N.useState({}),O=i||((re=(ee=l.customization)==null?void 0:ee.validationSchema)==null?void 0:re.verifyIdentity)||Rt,L=async R=>{R.preventDefault(),v({});const B=new FormData(R.currentTarget),$=Object.fromEntries(B.entries()),X={email:$[M]};try{O.parse(X)}catch(Y){if(Y instanceof I.z.ZodError){const te={};Y.errors.forEach(H=>{if(H.path[0]){const C=H.path[0].toString(),ce=C==="email"?M:C;te[ce]=H.message}}),v(te);return}}try{const Y=await b($);d&&d(Y)}catch{}},V=(s==null?void 0:s.Card)||"div",P=(s==null?void 0:s.Button)||"button",G=s==null?void 0:s.Input,T=((F=(J=l.customization)==null?void 0:J.labels)==null?void 0:F.forgotPasswordTitle)||"Forgot Password",A=((c=(D=l.customization)==null?void 0:D.labels)==null?void 0:c.forgotPasswordSubtitle)||"Enter your registered e-mail here, and we will send an OTP.",Q=(e==null?void 0:e.email)||((p=(h=l.customization)==null?void 0:h.labels)==null?void 0:p.forgotPasswordEmail)||((y=(f=l.customization)==null?void 0:f.labels)==null?void 0:y.email)||"E-mail",le=o||((a=(w=l.customization)==null?void 0:w.buttonText)==null?void 0:a.forgotPassword)||"Submit",se=(n==null?void 0:n.email)||((j=(u=l.customization)==null?void 0:u.placeholders)==null?void 0:j.forgotPasswordEmail)||((U=(S=l.customization)==null?void 0:S.placeholders)==null?void 0:U.email)||"E-mail",M=((z=(q=l.requestMapping)==null?void 0:q.forgotPassword)==null?void 0:z.email)||"email";return t.jsxs(V,{className:r.card,children:[t.jsxs("div",{style:{textAlign:"center",marginBottom:"20px"},children:[t.jsx("img",{src:"/img/confusion.png",alt:"",style:{width:"64px",height:"64px",marginBottom:"10px"},onError:R=>{R.currentTarget.style.display="none"}}),t.jsx("h1",{className:r.heading,children:T}),t.jsx("p",{className:r.subtext,children:k?"OTP has been dispatched to your email address.":A})]}),t.jsxs("form",{onSubmit:L,className:r.form,noValidate:!0,children:[t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:M,className:r.label,children:Q}),t.jsx("div",{className:r.inputWrapper,children:G?t.jsx(G,{type:"email",id:M,name:M,placeholder:se,error:_[M]}):t.jsx("input",{type:"email",id:M,name:M,placeholder:se,className:`${r.input} ${_[M]?r.inputError:""}`,required:!0,"aria-invalid":!!_[M],"aria-describedby":_[M]?`${M}-error`:void 0})}),_[M]&&t.jsx("span",{id:`${M}-error`,className:r.errorText,role:"alert",children:_[M]})]}),t.jsx(Re,{message:E,type:"error",style:{marginTop:"8px",marginBottom:"8px"},onDismiss:x}),t.jsx(P,{type:"submit",disabled:m,className:r.button,children:m?s!=null&&s.Loader?t.jsx(s.Loader,{}):"Loading...":le}),g&&t.jsx("div",{className:r.footerText,children:t.jsx("button",{type:"button",onClick:g,className:r.link,style:{background:"none",border:"none",padding:0},children:((K=(W=l.customization)==null?void 0:W.labels)==null?void 0:K.forgotPasswordBackToLoginLink)||"Back to Login"})})]})]})},Ft=({components:s,labels:e,buttonText:o,placeholders:n,validationSchema:i,email:d,name:g,token:l,urlParams:m,onSuccess:E,onResendSuccess:k})=>{var h,p,f,y,w,a,u,j,S,U,q,z,W,K,R,B,$,X,Y,te;const{config:b}=pe(),{loading:x,error:_,execute:v,resend:O,reset:L}=Nt(),[V,P]=N.useState({}),[G,T]=N.useState(null),A=((p=(h=b.requestMapping)==null?void 0:h.otp)==null?void 0:p.otp)||((y=(f=b.requestMapping)==null?void 0:f.login)==null?void 0:y.otp)||"otp",Q=i||((a=(w=b.customization)==null?void 0:w.validationSchema)==null?void 0:a.otp)||Lt,le=async H=>{var me;H.preventDefault(),P({}),T(null);const ce=((me=new FormData(H.currentTarget).get(A))==null?void 0:me.toString())||"";try{Q.parse({otp:ce})}catch(oe){if(oe instanceof I.z.ZodError){P({[A]:oe.errors[0].message});return}}const fe={[A]:ce,email:d||"",token:l||localStorage.getItem("Token")||""};try{const oe=await v(fe,m);E&&E(oe)}catch{}},se=async()=>{P({}),T(null);const H={Name:g||"",Email:d||"",ResendOtp:"Resend Otp",Token:l||localStorage.getItem("Token")||""};try{const C=await O(H,m);T("A new OTP has been sent."),k&&k(C)}catch{}},M=(s==null?void 0:s.Card)||"div",ee=(s==null?void 0:s.Button)||"button",re=s==null?void 0:s.Input,J=((j=(u=b.customization)==null?void 0:u.labels)==null?void 0:j.otpTitle)||"E-mail Verification",F=(e==null?void 0:e.otp)||((U=(S=b.customization)==null?void 0:S.labels)==null?void 0:U.otpLabel)||((z=(q=b.customization)==null?void 0:q.labels)==null?void 0:z.otp)||"OTP",D=o||((K=(W=b.customization)==null?void 0:W.buttonText)==null?void 0:K.otp)||"Submit",c=(n==null?void 0:n.otp)||((B=(R=b.customization)==null?void 0:R.placeholders)==null?void 0:B.otpPlaceholder)||((X=($=b.customization)==null?void 0:$.placeholders)==null?void 0:X.otp)||"OTP Code";return t.jsxs(M,{className:r.card,children:[t.jsxs("div",{style:{textAlign:"center",marginBottom:"20px"},children:[t.jsx("img",{src:"/img/otp-email-authentication-and-verification-method-vector-47553539.jpg",alt:"",style:{width:"80px",height:"80px",borderRadius:"50%",marginBottom:"10px",objectFit:"cover"},onError:H=>{H.currentTarget.style.display="none"}}),t.jsx("h1",{className:r.heading,children:J}),d&&t.jsxs("p",{className:r.subtext,children:["Verifying code sent to ",d]})]}),t.jsxs("form",{onSubmit:le,className:r.form,noValidate:!0,children:[t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:A,className:r.label,children:F}),t.jsx("div",{className:r.inputWrapper,children:re?t.jsx(re,{type:"text",id:A,name:A,placeholder:c,error:V[A]}):t.jsx("input",{type:"text",id:A,name:A,placeholder:c,className:`${r.input} ${V[A]?r.inputError:""}`,required:!0,inputMode:"numeric",pattern:"[0-9]*","aria-invalid":!!V[A],"aria-describedby":V[A]?`${A}-error`:void 0})}),V[A]&&t.jsx("span",{id:`${A}-error`,className:r.errorText,role:"alert",children:V[A]})]}),t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:t.jsx("button",{type:"button",onClick:se,className:r.link,style:{background:"none",border:"none",padding:0},children:((te=(Y=b.customization)==null?void 0:Y.labels)==null?void 0:te.otpResendLink)||"Resend OTP"})}),t.jsx(Re,{message:G,type:"success",style:{marginTop:"8px",marginBottom:"8px"},onDismiss:()=>T(null)}),t.jsx(Re,{message:_,type:"error",style:{marginTop:"8px",marginBottom:"8px"},onDismiss:L}),t.jsx(ee,{type:"submit",disabled:x,className:r.button,children:x?s!=null&&s.Loader?t.jsx(s.Loader,{}):"Loading...":D})]})]})},$t=({components:s,labels:e,buttonText:o,placeholders:n,validationSchema:i,urlParams:d,onSuccess:g})=>{var c,h,p,f,y,w,a,u,j,S,U,q,z,W,K,R,B,$,X,Y,te,H,C,ce,fe,me,oe,je;const{config:l}=pe(),{loading:m,error:E,success:k,execute:b,reset:x}=St(),[_,v]=N.useState({}),[O,L]=N.useState({pass:!0,verify:!0}),V=i||((h=(c=l.customization)==null?void 0:c.validationSchema)==null?void 0:h.resetPassword)||Ot,P=async ge=>{ge.preventDefault(),v({});const Te=new FormData(ge.currentTarget),we=Object.fromEntries(Te.entries()),_e={password:we[F],verifyPassword:we[D]};try{V.parse(_e)}catch(ye){if(ye instanceof I.z.ZodError){const xe={};ye.errors.forEach(he=>{if(he.path[0]){const ve=he.path[0].toString(),Pe=ve==="password"?F:ve==="verifyPassword"?D:ve;xe[Pe]=he.message}}),v(xe);return}}try{const{[D]:ye,...xe}=we,he=await b(xe,d);g&&g(he)}catch{}},G=(s==null?void 0:s.Card)||"div",T=(s==null?void 0:s.Button)||"button",A=s==null?void 0:s.Input,Q=((f=(p=l.customization)==null?void 0:p.labels)==null?void 0:f.resetPasswordTitle)||"Forget Password",le=((w=(y=l.customization)==null?void 0:y.labels)==null?void 0:w.resetPasswordSubtitle)||"Enter your registered e-mail here we'll send OTP in your email",se=(e==null?void 0:e.password)||((u=(a=l.customization)==null?void 0:a.labels)==null?void 0:u.resetPasswordPassword)||((S=(j=l.customization)==null?void 0:j.labels)==null?void 0:S.password)||"Password",M=(e==null?void 0:e.verifyPassword)||((q=(U=l.customization)==null?void 0:U.labels)==null?void 0:q.resetPasswordVerifyPassword)||((W=(z=l.customization)==null?void 0:z.labels)==null?void 0:W.verifyPassword)||"Verify Password",ee=o||((R=(K=l.customization)==null?void 0:K.buttonText)==null?void 0:R.resetPassword)||"Submit",re=(n==null?void 0:n.password)||(($=(B=l.customization)==null?void 0:B.placeholders)==null?void 0:$.resetPasswordPassword)||((Y=(X=l.customization)==null?void 0:X.placeholders)==null?void 0:Y.password)||"Password",J=(n==null?void 0:n.verifyPassword)||((H=(te=l.customization)==null?void 0:te.placeholders)==null?void 0:H.resetPasswordVerifyPassword)||((ce=(C=l.customization)==null?void 0:C.placeholders)==null?void 0:ce.verifyPassword)||"Verify Password",F=((me=(fe=l.requestMapping)==null?void 0:fe.resetPassword)==null?void 0:me.password)||"password",D=((je=(oe=l.requestMapping)==null?void 0:oe.resetPassword)==null?void 0:je.verifyPassword)||"verifyPassword";return t.jsxs(G,{className:r.card,children:[t.jsxs("div",{style:{textAlign:"center",marginBottom:"20px"},children:[t.jsx("img",{src:"/img/confusion.png",alt:"",style:{width:"64px",height:"64px",marginBottom:"10px"},onError:ge=>{ge.currentTarget.style.display="none"}}),t.jsx("h1",{className:r.heading,children:Q}),t.jsx("p",{className:r.subtext,children:k?"Your password has been successfully updated.":d!=null&&d.id?"Enter your new credentials below.":le})]}),t.jsxs("form",{onSubmit:P,className:r.form,noValidate:!0,children:[t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:F,className:r.label,children:se}),t.jsx("div",{className:r.inputWrapper,children:A?t.jsx(A,{type:O.pass?"password":"text",id:F,name:F,placeholder:re,error:_[F]}):t.jsxs(t.Fragment,{children:[t.jsx("input",{type:O.pass?"password":"text",id:F,name:F,placeholder:re,className:`${r.input} ${_[F]?r.inputError:""}`,required:!0,"aria-invalid":!!_[F],"aria-describedby":_[F]?`${F}-error`:void 0}),t.jsx("button",{type:"button",onClick:()=>L({...O,pass:!O.pass}),className:r.inputIcon,"aria-label":O.pass?"Show password":"Hide password",children:O.pass?t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}):t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})})]})}),_[F]&&t.jsx("span",{id:`${F}-error`,className:r.errorText,role:"alert",children:_[F]})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:D,className:r.label,children:M}),t.jsx("div",{className:r.inputWrapper,children:A?t.jsx(A,{type:O.verify?"password":"text",id:D,name:D,placeholder:J,error:_[D]}):t.jsxs(t.Fragment,{children:[t.jsx("input",{type:O.verify?"password":"text",id:D,name:D,placeholder:J,className:`${r.input} ${_[D]?r.inputError:""}`,required:!0,"aria-invalid":!!_[D],"aria-describedby":_[D]?`${D}-error`:void 0}),t.jsx("button",{type:"button",onClick:()=>L({...O,verify:!O.verify}),className:r.inputIcon,"aria-label":O.verify?"Show password":"Hide password",children:O.verify?t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}):t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})})]})}),_[D]&&t.jsx("span",{id:`${D}-error`,className:r.errorText,role:"alert",children:_[D]})]}),t.jsx(Re,{message:E,type:"error",style:{marginTop:"8px",marginBottom:"8px"},onDismiss:x}),t.jsx(T,{type:"submit",disabled:m,className:r.button,children:m?s!=null&&s.Loader?t.jsx(s.Loader,{}):"Loading...":ee})]})]})},Dt=({components:s,labels:e,buttonText:o,validationSchema:n,onSuccess:i,site:d,id:g})=>{var W,K,R,B,$,X,Y,te,H,C,ce,fe,me,oe,je,ge,Te,we,_e,ye,xe,he,ve,Pe,Me,Fe,$e,De,Be,qe,We,Ve,Ge,Ke,He,Ye,Je,Xe;const{user:l,config:m}=pe(),{loading:E,error:k,success:b,execute:x,reset:_}=Tt(),[v,O]=N.useState({}),[L,V]=N.useState(!0),[P,G]=N.useState({fullName:"",email:"",username:"",phoneNumber:"",password:"",profileUrl:"",city:"",state:"",country:"",postalcode:"",timezone:""});N.useEffect(()=>{l&&G({fullName:l.fullName||l.name||"",email:l.email||"",username:l.username||"",phoneNumber:l.phoneNumber||"",password:"",profileUrl:l.profileUrl||"",city:l.city||"",state:l.state||"",country:l.country||"",postalcode:l.postalcode||"",timezone:l.timezone||""})},[l]);const T=Le=>{const{name:Oe,value:Ee}=Le.target;G(ue=>({...ue,[Oe]:Ee}))},A=n||((K=(W=m.customization)==null?void 0:W.validationSchema)==null?void 0:K.updateUser)||Ct,Q=async Le=>{Le.preventDefault(),O({});const Oe={fullName:P.fullName,email:P.email,username:P.username,phoneNumber:P.phoneNumber,password:P.password,profileUrl:P.profileUrl,city:P.city,state:P.state,country:P.country,postalcode:P.postalcode,timezone:P.timezone},Ee={};Object.entries(Oe).forEach(([ue,ke])=>{ke!==""&&(Ee[ue]=ke)});try{A.parse(Ee)}catch(ue){if(ue instanceof I.z.ZodError){const ke={};ue.errors.forEach(Ce=>{if(Ce.path[0]){const de=Ce.path[0].toString(),Ie=de==="fullName"?f:de==="email"?y:de==="username"?w:de==="phoneNumber"?a:de==="profileUrl"?u:de==="password"?j:de==="city"?S:de==="state"?U:de==="country"?q:de==="postalcode"?z:de;ke[Ie]=Ce.message}}),O(ke);return}}try{const ue=await x(Ee,d,g);i&&i(ue)}catch{}},le=(s==null?void 0:s.Card)||"div",se=(s==null?void 0:s.Button)||"button",M=s==null?void 0:s.Input,ee=((B=(R=m.customization)==null?void 0:R.labels)==null?void 0:B.updateUserTitle)||"Update Profile",re=(e==null?void 0:e.fullName)||((X=($=m.customization)==null?void 0:$.labels)==null?void 0:X.updateUserFullName)||"Full Name",J=(e==null?void 0:e.email)||((te=(Y=m.customization)==null?void 0:Y.labels)==null?void 0:te.updateUserEmail)||"Email",F=(e==null?void 0:e.username)||((C=(H=m.customization)==null?void 0:H.labels)==null?void 0:C.updateUserUsername)||"Username",D=(e==null?void 0:e.phoneNumber)||((fe=(ce=m.customization)==null?void 0:ce.labels)==null?void 0:fe.updateUserPhone)||"Phone Number",c=(e==null?void 0:e.password)||((oe=(me=m.customization)==null?void 0:me.labels)==null?void 0:oe.updateUserPassword)||"New Password",h=(e==null?void 0:e.profileUrl)||((ge=(je=m.customization)==null?void 0:je.labels)==null?void 0:ge.updateUserProfileUrl)||"Profile URL",p=o||((we=(Te=m.customization)==null?void 0:Te.buttonText)==null?void 0:we.updateUser)||"Update Info",f=((ye=(_e=m.requestMapping)==null?void 0:_e.updateUser)==null?void 0:ye.fullName)||"fullName",y=((he=(xe=m.requestMapping)==null?void 0:xe.updateUser)==null?void 0:he.email)||"email",w=((Pe=(ve=m.requestMapping)==null?void 0:ve.updateUser)==null?void 0:Pe.username)||"username",a=((Fe=(Me=m.requestMapping)==null?void 0:Me.updateUser)==null?void 0:Fe.phoneNumber)||"phoneNumber",u=((De=($e=m.requestMapping)==null?void 0:$e.updateUser)==null?void 0:De.profileUrl)||"profileUrl",j=((qe=(Be=m.requestMapping)==null?void 0:Be.updateUser)==null?void 0:qe.password)||"password",S=((Ve=(We=m.requestMapping)==null?void 0:We.updateUser)==null?void 0:Ve.city)||"city",U=((Ke=(Ge=m.requestMapping)==null?void 0:Ge.updateUser)==null?void 0:Ke.state)||"state",q=((Ye=(He=m.requestMapping)==null?void 0:He.updateUser)==null?void 0:Ye.country)||"country",z=((Xe=(Je=m.requestMapping)==null?void 0:Je.updateUser)==null?void 0:Xe.postalcode)||"postalcode";return t.jsxs(le,{className:r.card,style:{maxWidth:"520px"},children:[t.jsx("h1",{className:r.heading,children:ee}),t.jsxs("form",{onSubmit:Q,className:r.form,noValidate:!0,children:[t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:f,className:r.label,children:re}),t.jsx("div",{className:r.inputWrapper,children:M?t.jsx(M,{type:"text",id:f,name:f,value:P.fullName,onChange:T,placeholder:"John Doe",error:v[f]}):t.jsx("input",{type:"text",id:f,name:f,value:P.fullName,onChange:T,placeholder:"John Doe",className:`${r.input} ${v[f]?r.inputError:""}`})}),v[f]&&t.jsx("span",{className:r.errorText,children:v[f]})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:y,className:r.label,children:J}),t.jsx("div",{className:r.inputWrapper,children:M?t.jsx(M,{type:"email",id:y,name:y,value:P.email,onChange:T,placeholder:"email@example.com",error:v[y]}):t.jsx("input",{type:"email",id:y,name:y,value:P.email,onChange:T,placeholder:"email@example.com",className:`${r.input} ${v[y]?r.inputError:""}`})}),v[y]&&t.jsx("span",{className:r.errorText,children:v[y]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:w,className:r.label,children:F}),t.jsx("input",{type:"text",id:w,name:w,value:P.username,onChange:T,placeholder:"username",className:r.input})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:a,className:r.label,children:D}),t.jsx("input",{type:"text",id:a,name:a,value:P.phoneNumber,onChange:T,placeholder:"+123456789",className:r.input})]})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:u,className:r.label,children:h}),t.jsx("div",{className:r.inputWrapper,children:t.jsx("input",{type:"text",id:u,name:u,value:P.profileUrl,onChange:T,placeholder:"https://example.com/avatar.png",className:`${r.input} ${v[u]?r.inputError:""}`})}),v[u]&&t.jsx("span",{className:r.errorText,children:v[u]})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:j,className:r.label,children:c}),t.jsxs("div",{className:r.inputWrapper,children:[t.jsx("input",{type:L?"password":"text",id:j,name:j,value:P.password,onChange:T,placeholder:"•••••••• (leave empty to keep current)",className:`${r.input} ${v[j]?r.inputError:""}`}),t.jsx("button",{type:"button",onClick:()=>V(!L),className:r.inputIcon,children:L?t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}):t.jsxs("svg",{className:r.eyeIcon,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]})})]}),v[j]&&t.jsx("span",{className:r.errorText,children:v[j]})]}),t.jsxs("div",{style:{marginTop:"4px",borderTop:"1px solid var(--auth-color-border, #e2e8f0)",paddingTop:"12px"},children:[t.jsx("h3",{style:{margin:"0 0 10px 0",fontSize:"0.9rem",fontWeight:600},children:"Location Details"}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:S,className:r.label,children:"City"}),t.jsx("input",{type:"text",id:S,name:S,value:P.city,onChange:T,placeholder:"City",className:r.input})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:U,className:r.label,children:"State"}),t.jsx("input",{type:"text",id:U,name:U,value:P.state,onChange:T,placeholder:"State",className:r.input})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px",marginTop:"10px"},children:[t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:q,className:r.label,children:"Country"}),t.jsx("input",{type:"text",id:q,name:q,value:P.country,onChange:T,placeholder:"Country",className:r.input})]}),t.jsxs("div",{className:r.formGroup,children:[t.jsx("label",{htmlFor:z,className:r.label,children:"Postal Code"}),t.jsx("input",{type:"text",id:z,name:z,value:P.postalcode,onChange:T,placeholder:"Postal Code",className:r.input})]})]})]}),t.jsx(Re,{message:b?"Profile updated successfully.":null,type:"success",style:{marginTop:"12px",marginBottom:"8px"},onDismiss:_}),t.jsx(Re,{message:k,type:"error",style:{marginTop:"12px",marginBottom:"8px"},onDismiss:_}),t.jsx(se,{type:"submit",disabled:E,className:r.button,style:{marginTop:"10px"},children:E?s!=null&&s.Loader?t.jsx(s.Loader,{}):"Updating...":p})]})]})},js=({view:s="login",onSuccess:e})=>{const[o,n]=N.useState(s),[i,d]=N.useState(""),[g,l]=N.useState(null),{isAuthenticated:m}=pe();return N.useEffect(()=>{n(s)},[s]),N.useEffect(()=>{const E=x=>{if(x&&x.email)d(x.email);else{const _=sessionStorage.getItem("auth_registration_email");_&&d(_)}n("otp")},k=x=>{e&&e("login",x)},b=x=>{n("login"),e&&e("resetPassword",x)};return ae.on("OTP_SENT",E),ae.on("LOGIN_SUCCESS",k),ae.on("PASSWORD_RESET",b),()=>{ae.off("OTP_SENT",E),ae.off("LOGIN_SUCCESS",k),ae.off("PASSWORD_RESET",b)}},[e]),m&&o!=="updateUser"&&o!=="resetPassword"?null:t.jsxs(t.Fragment,{children:[o==="login"&&t.jsx(At,{onForgotPasswordClick:()=>n("forgotPassword"),onSignupClick:()=>n("signup")}),o==="signup"&&t.jsx(Ut,{onLoginClick:()=>n("login")}),o==="forgotPassword"&&t.jsx(Mt,{onBackToLoginClick:()=>n("login"),onSuccess:E=>{E&&E.email&&d(E.email),n("otp")}}),o==="otp"&&t.jsx(Ft,{email:i,onSuccess:E=>{const k=(E==null?void 0:E.accessToken)||(E==null?void 0:E.token);k&&(l(k),n("resetPassword")),e&&e("otp",E)}}),o==="resetPassword"&&t.jsx($t,{urlParams:g?{token:g}:void 0}),o==="updateUser"&&t.jsx(Dt,{onSuccess:E=>{e&&e("updateUser",E)}})]})};exports.Alert=Re;exports.AuthContext=mt;exports.AuthProvider=Qt;exports.AuthSdkError=ze;exports.AuthWidget=js;exports.ForgotPassword=Mt;exports.GoogleLogin=ht;exports.Login=At;exports.OTP=Ft;exports.ResetPassword=$t;exports.Signup=Ut;exports.UpdateUser=Dt;exports.decodeJWT=st;exports.eventService=ae;exports.isTokenExpired=bt;exports.loginSchema=_t;exports.normalizeError=Se;exports.otpEmailSchema=Pt;exports.otpSchema=Lt;exports.otpSubmitSchema=It;exports.resetPasswordSchema=Ot;exports.signupSchema=zt;exports.updateUserSchema=Ct;exports.useAuth=pe;exports.useLogin=jt;exports.useOtp=Nt;exports.useResetPassword=St;exports.useSignup=Et;exports.useUpdateUser=Tt;exports.useVerifyIdentity=kt;exports.verifyIdentitySchema=Rt;
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|