@proveanything/smartlinks-auth-ui 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +385 -228
- package/dist/components/AccountManagement.d.ts.map +1 -1
- package/dist/components/AuthContainer.d.ts +1 -0
- package/dist/components/AuthContainer.d.ts.map +1 -1
- package/dist/components/AuthUIPreview.d.ts +1 -0
- package/dist/components/AuthUIPreview.d.ts.map +1 -1
- package/dist/components/ClaimUI.d.ts +4 -0
- package/dist/components/ClaimUI.d.ts.map +1 -0
- package/dist/components/EmailAuthForm.d.ts +2 -1
- package/dist/components/EmailAuthForm.d.ts.map +1 -1
- package/dist/context/AuthContext.d.ts +10 -3
- package/dist/context/AuthContext.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.css.map +1 -1
- package/dist/index.esm.js +804 -116
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +804 -115
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +66 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/persistentStorage.d.ts +39 -0
- package/dist/utils/persistentStorage.d.ts.map +1 -0
- package/dist/utils/tokenStorage.d.ts +23 -10
- package/dist/utils/tokenStorage.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,31 +1,65 @@
|
|
|
1
1
|
# @smartlinks/auth-ui
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A complete, drop-in React authentication and account management solution built for the Smartlinks platform. Provides beautiful, customizable UI components for authentication flows, session management, and user account operations with seamless Smartlinks SDK integration.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### Authentication
|
|
8
|
+
- 🔐 **Multiple Auth Methods**: Email/Password, Google OAuth, Phone/SMS, Magic Links
|
|
8
9
|
- 🎨 **Beautiful Pre-built UI**: Professional, responsive authentication flows
|
|
9
|
-
- 🪙 **Bearer
|
|
10
|
-
- 🗂️ **Session Management**: Built-in AuthProvider, useAuth hook, and
|
|
10
|
+
- 🪙 **JWT Bearer Tokens**: Automatic Smartlinks SDK integration with bearer token management
|
|
11
|
+
- 🗂️ **Session Management**: Built-in AuthProvider, useAuth hook, ProtectedRoute, and cross-tab sync
|
|
11
12
|
- 🏢 **Multi-Tenant Support**: Client ID for identifying different systems/tenants
|
|
12
|
-
- 📊 **Account Data**: Store custom metadata per user account
|
|
13
|
-
- 🔗 **
|
|
14
|
-
-
|
|
13
|
+
- 📊 **Custom Account Data**: Store custom metadata per user account
|
|
14
|
+
- 🔗 **Deep Link Support**: Email verification, password reset, magic link flows
|
|
15
|
+
- 📧 **Passwordless Login**: Magic link authentication via email
|
|
16
|
+
|
|
17
|
+
### Account Management
|
|
18
|
+
- 👤 **Profile Management**: Update display name and contact information
|
|
19
|
+
- 🔑 **Password Changes**: Secure password update flow for authenticated users
|
|
20
|
+
- 📧 **Email Changes**: Change email with verification flow
|
|
21
|
+
- 📱 **Phone Updates**: Update phone number with SMS verification
|
|
22
|
+
- 🗑️ **Account Deletion**: Self-service account deletion
|
|
23
|
+
- 🎯 **Product Claiming**: Claim physical products/proofs with custom attestations
|
|
24
|
+
|
|
25
|
+
### Developer Experience
|
|
26
|
+
- ⚡ **Lightweight**: Minimal dependencies, integrates with Smartlinks SDK
|
|
15
27
|
- 📱 **Fully Responsive**: Works seamlessly on mobile and desktop
|
|
16
|
-
- ♿ **Accessible**: WCAG compliant
|
|
28
|
+
- ♿ **Accessible**: WCAG compliant forms and interactions
|
|
29
|
+
- 🎨 **Highly Customizable**: Extensive theming and branding options
|
|
30
|
+
- 🔄 **Real-time Sync**: Cross-tab authentication state synchronization
|
|
31
|
+
- 💾 **Smart Caching**: Account info caching with configurable TTL
|
|
32
|
+
- 🎣 **Auth State Callbacks**: Subscribe to login, logout, and token refresh events
|
|
33
|
+
- 📘 **TypeScript First**: Full type definitions included
|
|
17
34
|
|
|
18
35
|
## Installation
|
|
19
36
|
|
|
20
37
|
```bash
|
|
21
|
-
npm install @smartlinks/auth-ui
|
|
38
|
+
npm install @smartlinks/auth-ui @proveanything/smartlinks
|
|
22
39
|
```
|
|
23
40
|
|
|
41
|
+
**Note**: This package requires the Smartlinks SDK (`@proveanything/smartlinks`) as a peer dependency.
|
|
42
|
+
|
|
24
43
|
## Quick Start
|
|
25
44
|
|
|
26
|
-
### 1.
|
|
45
|
+
### 1. Initialize Smartlinks SDK
|
|
46
|
+
|
|
47
|
+
Initialize the Smartlinks SDK at the top level of your application:
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
// src/App.tsx or src/main.tsx
|
|
51
|
+
import * as smartlinks from '@proveanything/smartlinks';
|
|
52
|
+
|
|
53
|
+
// Initialize the SDK before your app renders
|
|
54
|
+
smartlinks.initializeApi({
|
|
55
|
+
baseUrl: 'https://smartlinks.app/api/v1',
|
|
56
|
+
proxyMode: false, // Set to true if running in iframe
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 2. Import the CSS (Required!)
|
|
27
61
|
|
|
28
|
-
Add this import to your app's entry point
|
|
62
|
+
Add this import to your app's entry point:
|
|
29
63
|
|
|
30
64
|
```tsx
|
|
31
65
|
import '@smartlinks/auth-ui/dist/index.css';
|
|
@@ -33,28 +67,36 @@ import '@smartlinks/auth-ui/dist/index.css';
|
|
|
33
67
|
|
|
34
68
|
**Important**: Without this CSS import, the authentication UI will not be styled correctly.
|
|
35
69
|
|
|
36
|
-
###
|
|
70
|
+
### 3. Wrap Your App with AuthProvider
|
|
37
71
|
|
|
38
72
|
```tsx
|
|
39
|
-
import {
|
|
40
|
-
import '@smartlinks/auth-ui/dist/index.css';
|
|
73
|
+
import { AuthProvider } from '@smartlinks/auth-ui';
|
|
74
|
+
import '@smartlinks/auth-ui/dist/index.css';
|
|
41
75
|
|
|
42
76
|
function App() {
|
|
43
77
|
return (
|
|
44
|
-
<AuthProvider
|
|
78
|
+
<AuthProvider
|
|
79
|
+
clientId="your-client-123"
|
|
80
|
+
clientName="Acme Corp"
|
|
81
|
+
>
|
|
45
82
|
<YourApp />
|
|
46
83
|
</AuthProvider>
|
|
47
84
|
);
|
|
48
85
|
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 4. Use the Authentication UI
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { SmartlinksAuthUI, useAuth } from '@smartlinks/auth-ui';
|
|
49
92
|
|
|
50
93
|
function YourApp() {
|
|
51
|
-
const { user,
|
|
94
|
+
const { user, isAuthenticated, logout } = useAuth();
|
|
52
95
|
|
|
53
96
|
if (isAuthenticated) {
|
|
54
97
|
return (
|
|
55
98
|
<div>
|
|
56
|
-
<h1>Welcome, {user
|
|
57
|
-
<p>Account: {accountData?.companyName}</p>
|
|
99
|
+
<h1>Welcome, {user?.displayName || user?.email}!</h1>
|
|
58
100
|
<button onClick={logout}>Logout</button>
|
|
59
101
|
</div>
|
|
60
102
|
);
|
|
@@ -62,72 +104,192 @@ function YourApp() {
|
|
|
62
104
|
|
|
63
105
|
return (
|
|
64
106
|
<SmartlinksAuthUI
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
companyName: "Acme Corp",
|
|
70
|
-
plan: "pro"
|
|
71
|
-
}}
|
|
72
|
-
onAuthSuccess={(token, user, accountData) => {
|
|
73
|
-
console.log('Authenticated!', { token, user, accountData });
|
|
107
|
+
clientId="your-client-123"
|
|
108
|
+
onAuthSuccess={(response) => {
|
|
109
|
+
console.log('Authenticated!', response.user);
|
|
110
|
+
// Optional: redirect or update UI
|
|
74
111
|
}}
|
|
75
|
-
enabledProviders={['email', 'google', 'phone']}
|
|
76
112
|
/>
|
|
77
113
|
);
|
|
78
114
|
}
|
|
79
115
|
```
|
|
80
116
|
|
|
81
|
-
##
|
|
117
|
+
## Components
|
|
82
118
|
|
|
83
119
|
### SmartlinksAuthUI
|
|
84
120
|
|
|
121
|
+
Main authentication component with login, registration, password reset, and provider authentication.
|
|
122
|
+
|
|
123
|
+
#### Props
|
|
124
|
+
|
|
85
125
|
| Prop | Type | Required | Description |
|
|
86
126
|
|------|------|----------|-------------|
|
|
87
|
-
| `
|
|
88
|
-
| `clientId` | string | **Yes** | **REQUIRED** - Client identifier used in all API calls |
|
|
127
|
+
| `clientId` | string | **Yes** | Client identifier for your application |
|
|
89
128
|
| `clientName` | string | No | Client name for branded emails |
|
|
90
129
|
| `accountData` | Record<string, any> | No | Custom metadata to store on registration |
|
|
91
|
-
| `onAuthSuccess` | (
|
|
130
|
+
| `onAuthSuccess` | (response: AuthResponse) => void | No | Callback when authentication succeeds |
|
|
92
131
|
| `onAuthError` | (error: Error) => void | No | Callback when authentication fails |
|
|
93
|
-
| `enabledProviders` | Array<'email' \| 'google' \| 'phone'> | No | Auth providers to enable (default: all) |
|
|
94
132
|
| `redirectUrl` | string | No | URL to redirect after auth (default: current page) |
|
|
95
|
-
| `
|
|
133
|
+
| `launchMode` | 'login' \| 'signup' | No | Initial view (default: 'login') |
|
|
134
|
+
| `customization` | AuthUIConfig | No | UI customization (colors, fonts, logo) |
|
|
135
|
+
|
|
136
|
+
#### Example
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
<SmartlinksAuthUI
|
|
140
|
+
clientId="your-client-123"
|
|
141
|
+
clientName="Acme Corp"
|
|
142
|
+
accountData={{
|
|
143
|
+
companyName: "Acme Corp",
|
|
144
|
+
plan: "enterprise"
|
|
145
|
+
}}
|
|
146
|
+
onAuthSuccess={(response) => {
|
|
147
|
+
console.log('User:', response.user);
|
|
148
|
+
console.log('Token:', response.token);
|
|
149
|
+
console.log('Account Data:', response.accountData);
|
|
150
|
+
}}
|
|
151
|
+
onAuthError={(error) => {
|
|
152
|
+
console.error('Auth error:', error);
|
|
153
|
+
}}
|
|
154
|
+
launchMode="signup"
|
|
155
|
+
/>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### AccountManagement
|
|
159
|
+
|
|
160
|
+
Account management component for authenticated users to update their profile, change passwords, update contact info, and delete their account.
|
|
161
|
+
|
|
162
|
+
#### Props
|
|
163
|
+
|
|
164
|
+
| Prop | Type | Required | Description |
|
|
165
|
+
|------|------|----------|-------------|
|
|
166
|
+
| `clientId` | string | **Yes** | Client identifier for your application |
|
|
167
|
+
| `showHeader` | boolean | No | Show component header (default: false) |
|
|
168
|
+
| `onProfileUpdate` | () => void | No | Callback after profile update |
|
|
169
|
+
| `onAccountDelete` | () => void | No | Callback after account deletion |
|
|
170
|
+
|
|
171
|
+
#### Example
|
|
172
|
+
|
|
173
|
+
```tsx
|
|
174
|
+
import { AccountManagement } from '@smartlinks/auth-ui';
|
|
175
|
+
|
|
176
|
+
<AccountManagement
|
|
177
|
+
clientId="your-client-123"
|
|
178
|
+
onProfileUpdate={() => {
|
|
179
|
+
console.log('Profile updated!');
|
|
180
|
+
}}
|
|
181
|
+
onAccountDelete={() => {
|
|
182
|
+
console.log('Account deleted');
|
|
183
|
+
// Redirect to home or login
|
|
184
|
+
}}
|
|
185
|
+
/>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### SmartlinksClaimUI
|
|
189
|
+
|
|
190
|
+
Product claiming component for authenticating users and claiming physical products/proofs with optional custom questions.
|
|
191
|
+
|
|
192
|
+
#### Props
|
|
193
|
+
|
|
194
|
+
| Prop | Type | Required | Description |
|
|
195
|
+
|------|------|----------|-------------|
|
|
196
|
+
| `clientId` | string | **Yes** | Client identifier for your application |
|
|
197
|
+
| `collectionId` | string | **Yes** | Collection ID of the product |
|
|
198
|
+
| `productId` | string | **Yes** | Product ID to claim |
|
|
199
|
+
| `proofId` | string | **Yes** | Specific proof ID to claim |
|
|
200
|
+
| `additionalQuestions` | ClaimField[] | No | Custom questions for claim attestations |
|
|
201
|
+
| `onClaimSuccess` | (result: ClaimResult) => void | **Yes** | Callback when claim succeeds |
|
|
202
|
+
| `onClaimError` | (error: Error) => void | No | Callback when claim fails |
|
|
203
|
+
|
|
204
|
+
#### Example
|
|
205
|
+
|
|
206
|
+
```tsx
|
|
207
|
+
import { SmartlinksClaimUI } from '@smartlinks/auth-ui';
|
|
208
|
+
|
|
209
|
+
<SmartlinksClaimUI
|
|
210
|
+
clientId="your-client-123"
|
|
211
|
+
collectionId="col_abc123"
|
|
212
|
+
productId="prod_xyz789"
|
|
213
|
+
proofId="proof_def456"
|
|
214
|
+
additionalQuestions={[
|
|
215
|
+
{
|
|
216
|
+
id: 'serial_number',
|
|
217
|
+
label: 'Serial Number',
|
|
218
|
+
type: 'text',
|
|
219
|
+
required: true
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
id: 'purchase_date',
|
|
223
|
+
label: 'Purchase Date',
|
|
224
|
+
type: 'date',
|
|
225
|
+
required: false
|
|
226
|
+
}
|
|
227
|
+
]}
|
|
228
|
+
onClaimSuccess={(result) => {
|
|
229
|
+
console.log('Claimed!', result.proof);
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
```
|
|
96
233
|
|
|
97
234
|
## Session Management
|
|
98
235
|
|
|
99
236
|
### AuthProvider
|
|
100
237
|
|
|
101
|
-
|
|
238
|
+
The AuthProvider component manages authentication state across your application. It handles token persistence, cross-tab synchronization, and automatic token refresh.
|
|
102
239
|
|
|
103
|
-
|
|
104
|
-
|
|
240
|
+
#### Props
|
|
241
|
+
|
|
242
|
+
| Prop | Type | Required | Description |
|
|
243
|
+
|------|------|----------|-------------|
|
|
244
|
+
| `clientId` | string | **Yes** | Client identifier for your application |
|
|
245
|
+
| `clientName` | string | No | Client name for branded communications |
|
|
246
|
+
| `accountCacheTTL` | number | No | Account cache TTL in ms (default: 300000 / 5 min) |
|
|
247
|
+
| `preloadAccountInfo` | boolean | No | Fetch account info on login (default: false) |
|
|
248
|
+
|
|
249
|
+
#### Example
|
|
105
250
|
|
|
106
|
-
|
|
251
|
+
```tsx
|
|
252
|
+
<AuthProvider
|
|
253
|
+
clientId="your-client-123"
|
|
254
|
+
clientName="Acme Corp"
|
|
255
|
+
accountCacheTTL={600000} // 10 minutes
|
|
256
|
+
preloadAccountInfo={true}
|
|
257
|
+
>
|
|
107
258
|
<App />
|
|
108
259
|
</AuthProvider>
|
|
109
260
|
```
|
|
110
261
|
|
|
111
262
|
### useAuth Hook
|
|
112
263
|
|
|
113
|
-
Access authentication state anywhere in your app:
|
|
264
|
+
Access authentication state and methods anywhere in your app:
|
|
114
265
|
|
|
115
266
|
```tsx
|
|
116
267
|
import { useAuth } from '@smartlinks/auth-ui';
|
|
117
268
|
|
|
118
269
|
function MyComponent() {
|
|
119
270
|
const {
|
|
120
|
-
user, // Current user object
|
|
121
|
-
token, //
|
|
271
|
+
user, // Current user object (email, displayName, uid)
|
|
272
|
+
token, // Current JWT bearer token
|
|
122
273
|
accountData, // Custom account metadata
|
|
274
|
+
accountInfo, // Cached account information
|
|
123
275
|
isAuthenticated, // Boolean auth status
|
|
124
276
|
isLoading, // Loading state
|
|
125
|
-
login, //
|
|
277
|
+
login, // Manual login function
|
|
126
278
|
logout, // Logout function
|
|
127
279
|
getToken, // Get current token
|
|
280
|
+
getAccount, // Fetch account info (uses cache)
|
|
281
|
+
refreshAccount, // Force refresh account info
|
|
128
282
|
} = useAuth();
|
|
129
283
|
|
|
130
|
-
|
|
284
|
+
return (
|
|
285
|
+
<div>
|
|
286
|
+
{isAuthenticated ? (
|
|
287
|
+
<p>Welcome, {user.displayName}!</p>
|
|
288
|
+
) : (
|
|
289
|
+
<p>Please log in</p>
|
|
290
|
+
)}
|
|
291
|
+
</div>
|
|
292
|
+
);
|
|
131
293
|
}
|
|
132
294
|
```
|
|
133
295
|
|
|
@@ -138,239 +300,227 @@ Protect routes that require authentication:
|
|
|
138
300
|
```tsx
|
|
139
301
|
import { ProtectedRoute } from '@smartlinks/auth-ui';
|
|
140
302
|
|
|
141
|
-
<ProtectedRoute
|
|
303
|
+
<ProtectedRoute
|
|
304
|
+
fallback={<LoginPage />}
|
|
305
|
+
redirectTo="/login"
|
|
306
|
+
>
|
|
142
307
|
<DashboardPage />
|
|
143
308
|
</ProtectedRoute>
|
|
144
309
|
```
|
|
145
310
|
|
|
146
|
-
|
|
311
|
+
### Auth State Change Callbacks
|
|
147
312
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
Use `clientId` to identify which system/tenant is using the auth:
|
|
313
|
+
Subscribe to authentication events:
|
|
151
314
|
|
|
152
315
|
```tsx
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
316
|
+
import { onAuthStateChange } from '@smartlinks/auth-ui';
|
|
317
|
+
|
|
318
|
+
useEffect(() => {
|
|
319
|
+
const unsubscribe = onAuthStateChange((event, session) => {
|
|
320
|
+
switch (event) {
|
|
321
|
+
case 'LOGIN':
|
|
322
|
+
console.log('User logged in:', session.user);
|
|
323
|
+
navigate('/dashboard');
|
|
324
|
+
break;
|
|
325
|
+
case 'LOGOUT':
|
|
326
|
+
console.log('User logged out');
|
|
327
|
+
navigate('/');
|
|
328
|
+
break;
|
|
329
|
+
case 'CROSS_TAB_SYNC':
|
|
330
|
+
console.log('Auth state synced from another tab');
|
|
331
|
+
break;
|
|
332
|
+
case 'TOKEN_REFRESH':
|
|
333
|
+
console.log('Token refreshed');
|
|
334
|
+
break;
|
|
335
|
+
case 'ACCOUNT_REFRESH':
|
|
336
|
+
console.log('Account info refreshed');
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
return () => unsubscribe();
|
|
342
|
+
}, []);
|
|
160
343
|
```
|
|
161
344
|
|
|
162
|
-
|
|
345
|
+
## Account Caching
|
|
163
346
|
|
|
164
|
-
|
|
347
|
+
The auth module includes intelligent account info caching to reduce API calls:
|
|
165
348
|
|
|
166
349
|
```tsx
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
console.log('Company:', accountData.companyName);
|
|
180
|
-
console.log('Plan:', accountData.plan);
|
|
181
|
-
}}
|
|
182
|
-
/>
|
|
350
|
+
const { getAccount, refreshAccount, accountInfo } = useAuth();
|
|
351
|
+
|
|
352
|
+
// Get account (uses cache if fresh)
|
|
353
|
+
const account = await getAccount();
|
|
354
|
+
|
|
355
|
+
// Force refresh
|
|
356
|
+
const freshAccount = await getAccount(true);
|
|
357
|
+
// or
|
|
358
|
+
const freshAccount = await refreshAccount();
|
|
359
|
+
|
|
360
|
+
// Access cached data synchronously
|
|
361
|
+
const cachedAccount = accountInfo;
|
|
183
362
|
```
|
|
184
363
|
|
|
185
|
-
|
|
364
|
+
**Configuration:**
|
|
365
|
+
- Default cache TTL: 5 minutes
|
|
366
|
+
- Configure via `accountCacheTTL` prop on AuthProvider
|
|
367
|
+
- Enable automatic preload with `preloadAccountInfo={true}`
|
|
368
|
+
|
|
369
|
+
See [ACCOUNT_CACHING.md](./ACCOUNT_CACHING.md) for detailed documentation.
|
|
186
370
|
|
|
187
|
-
## Authentication
|
|
371
|
+
## Authentication Methods
|
|
372
|
+
|
|
373
|
+
### Email/Password
|
|
374
|
+
|
|
375
|
+
Standard email and password authentication with registration, login, password reset, and email verification.
|
|
188
376
|
|
|
189
|
-
### Email/Password Login
|
|
190
377
|
```tsx
|
|
191
378
|
<SmartlinksAuthUI
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
enabledProviders={['email']}
|
|
379
|
+
clientId="your-client-123"
|
|
380
|
+
launchMode="signup"
|
|
195
381
|
/>
|
|
196
382
|
```
|
|
197
383
|
|
|
198
384
|
### Google OAuth
|
|
385
|
+
|
|
386
|
+
One-click Google authentication with automatic account creation.
|
|
387
|
+
|
|
199
388
|
```tsx
|
|
200
389
|
<SmartlinksAuthUI
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
enabledProviders={['google']}
|
|
390
|
+
clientId="your-client-123"
|
|
391
|
+
// Google Auth is enabled by default
|
|
204
392
|
/>
|
|
205
393
|
```
|
|
206
394
|
|
|
207
|
-
### Phone/SMS
|
|
395
|
+
### Phone/SMS
|
|
396
|
+
|
|
397
|
+
Phone number authentication with SMS verification codes.
|
|
398
|
+
|
|
208
399
|
```tsx
|
|
209
400
|
<SmartlinksAuthUI
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
enabledProviders={['phone']}
|
|
401
|
+
clientId="your-client-123"
|
|
402
|
+
// Phone auth is enabled by default
|
|
213
403
|
/>
|
|
214
404
|
```
|
|
215
405
|
|
|
216
|
-
|
|
406
|
+
### Magic Links
|
|
217
407
|
|
|
218
|
-
|
|
408
|
+
Passwordless authentication via email magic links.
|
|
219
409
|
|
|
220
|
-
|
|
221
|
-
|
|
410
|
+
```tsx
|
|
411
|
+
<SmartlinksAuthUI
|
|
412
|
+
clientId="your-client-123"
|
|
413
|
+
// Magic links are enabled by default
|
|
414
|
+
/>
|
|
415
|
+
```
|
|
222
416
|
|
|
223
|
-
##
|
|
417
|
+
## Customization
|
|
224
418
|
|
|
225
|
-
|
|
419
|
+
### Branding & Theming
|
|
226
420
|
|
|
227
|
-
|
|
228
|
-
```json
|
|
229
|
-
{
|
|
230
|
-
"email": "user@example.com",
|
|
231
|
-
"password": "password123"
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
Response: `{ "token": "bearer_token", "user": {...} }`
|
|
235
|
-
|
|
236
|
-
### POST /api/v1/authkit/:clientId/auth/register
|
|
237
|
-
```json
|
|
238
|
-
{
|
|
239
|
-
"email": "user@example.com",
|
|
240
|
-
"password": "password123",
|
|
241
|
-
"displayName": "John Doe"
|
|
242
|
-
}
|
|
243
|
-
```
|
|
244
|
-
Response: `{ "token": "bearer_token", "user": {...} }`
|
|
421
|
+
Customize colors, fonts, and logo via the admin interface or programmatically:
|
|
245
422
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
423
|
+
```tsx
|
|
424
|
+
<SmartlinksAuthUI
|
|
425
|
+
clientId="your-client-123"
|
|
426
|
+
customization={{
|
|
427
|
+
branding: {
|
|
428
|
+
logoUrl: "https://yourdomain.com/logo.png",
|
|
429
|
+
title: "Welcome to Acme",
|
|
430
|
+
subtitle: "Sign in to your account",
|
|
431
|
+
primaryColor: "#6366f1",
|
|
432
|
+
secondaryColor: "#4f46e5",
|
|
433
|
+
backgroundColor: "#f0f9ff",
|
|
434
|
+
fontFamily: "Inter, sans-serif"
|
|
435
|
+
}
|
|
436
|
+
}}
|
|
437
|
+
/>
|
|
251
438
|
```
|
|
252
|
-
Response: `{ "token": "bearer_token", "user": {...} }`
|
|
253
439
|
|
|
254
|
-
###
|
|
255
|
-
```json
|
|
256
|
-
{
|
|
257
|
-
"phoneNumber": "+1234567890"
|
|
258
|
-
}
|
|
259
|
-
```
|
|
260
|
-
Response: `{ "verificationId": "xxx" }`
|
|
440
|
+
### Provider Configuration
|
|
261
441
|
|
|
262
|
-
|
|
263
|
-
```json
|
|
264
|
-
{
|
|
265
|
-
"verificationId": "xxx",
|
|
266
|
-
"code": "123456"
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
Response: `{ "token": "bearer_token", "user": {...} }`
|
|
442
|
+
Configure which authentication providers are available and their display order through the Smartlinks admin interface.
|
|
270
443
|
|
|
271
|
-
###
|
|
272
|
-
```json
|
|
273
|
-
{
|
|
274
|
-
"email": "user@example.com"
|
|
275
|
-
}
|
|
276
|
-
```
|
|
277
|
-
Response: `{ "success": true }`
|
|
444
|
+
### Email Templates
|
|
278
445
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
```
|
|
285
|
-
Response: `{ "valid": true, "email": "user@example.com" }`
|
|
446
|
+
Customize email templates for password reset, email verification, and magic links through the admin interface with support for:
|
|
447
|
+
- Custom logos and hero images
|
|
448
|
+
- Branded colors and fonts
|
|
449
|
+
- Custom intro text and CTAs
|
|
450
|
+
- Footer links and company information
|
|
286
451
|
|
|
287
|
-
|
|
288
|
-
```json
|
|
289
|
-
{
|
|
290
|
-
"token": "reset_token_from_email",
|
|
291
|
-
"newPassword": "newpass123"
|
|
292
|
-
}
|
|
293
|
-
```
|
|
294
|
-
Response: `{ "success": true }`
|
|
295
|
-
|
|
296
|
-
### GET /api/v1/authkit/:clientId/config
|
|
297
|
-
Get UI configuration for the client (public, cached)
|
|
298
|
-
|
|
299
|
-
Response:
|
|
300
|
-
```json
|
|
301
|
-
{
|
|
302
|
-
"title": "Welcome to Acme",
|
|
303
|
-
"subtitle": "Sign in to your account",
|
|
304
|
-
"primaryColor": "#3B82F6",
|
|
305
|
-
"buttonStyle": "rounded",
|
|
306
|
-
"enabledProviders": ["email", "google"]
|
|
307
|
-
}
|
|
308
|
-
```
|
|
452
|
+
See [CUSTOMIZATION_GUIDE.md](./CUSTOMIZATION_GUIDE.md) for detailed customization options.
|
|
309
453
|
|
|
310
|
-
##
|
|
454
|
+
## Advanced Features
|
|
311
455
|
|
|
312
|
-
###
|
|
456
|
+
### Multi-Tenant Support
|
|
313
457
|
|
|
314
|
-
The
|
|
458
|
+
The `clientId` parameter enables multi-tenant authentication, allowing different applications or customers to use the same auth infrastructure with isolated configurations:
|
|
315
459
|
|
|
316
460
|
```tsx
|
|
317
|
-
|
|
318
|
-
|
|
461
|
+
// App 1
|
|
462
|
+
<SmartlinksAuthUI clientId="app-1-prod" />
|
|
319
463
|
|
|
320
|
-
|
|
464
|
+
// App 2
|
|
465
|
+
<SmartlinksAuthUI clientId="app-2-prod" />
|
|
466
|
+
```
|
|
321
467
|
|
|
322
|
-
###
|
|
468
|
+
### Custom Account Data
|
|
323
469
|
|
|
324
|
-
|
|
470
|
+
Store custom metadata per user account during registration:
|
|
325
471
|
|
|
326
472
|
```tsx
|
|
327
473
|
<SmartlinksAuthUI
|
|
328
|
-
apiEndpoint="https://api.smartlinks.com"
|
|
329
474
|
clientId="your-client-123"
|
|
330
|
-
|
|
331
|
-
|
|
475
|
+
accountData={{
|
|
476
|
+
companyName: "Acme Corp",
|
|
477
|
+
plan: "enterprise",
|
|
478
|
+
seats: 50,
|
|
479
|
+
customFields: {
|
|
480
|
+
industry: "Technology",
|
|
481
|
+
region: "North America"
|
|
482
|
+
}
|
|
483
|
+
}}
|
|
332
484
|
/>
|
|
333
485
|
```
|
|
334
486
|
|
|
335
|
-
###
|
|
487
|
+
### Deep Link Handling
|
|
336
488
|
|
|
337
|
-
|
|
489
|
+
The component automatically handles URL-based authentication flows:
|
|
338
490
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
customization={{
|
|
343
|
-
branding: {
|
|
344
|
-
primaryColor: "#6366f1",
|
|
345
|
-
secondaryColor: "#4f46e5",
|
|
346
|
-
backgroundColor: "#f0f9ff",
|
|
347
|
-
fontFamily: "Inter, sans-serif"
|
|
348
|
-
}
|
|
349
|
-
}}
|
|
350
|
-
/>
|
|
351
|
-
```
|
|
491
|
+
- **Email Verification**: `?mode=verifyEmail&token=xxx`
|
|
492
|
+
- **Password Reset**: `?mode=resetPassword&token=xxx`
|
|
493
|
+
- **Magic Links**: `?mode=magicLink&token=xxx`
|
|
352
494
|
|
|
353
|
-
|
|
354
|
-
```css
|
|
355
|
-
/* In your app's CSS file */
|
|
356
|
-
.auth-container {
|
|
357
|
-
/* Your custom styles */
|
|
358
|
-
}
|
|
495
|
+
### Cross-Tab Synchronization
|
|
359
496
|
|
|
360
|
-
.
|
|
361
|
-
/* Your custom button styles */
|
|
362
|
-
}
|
|
363
|
-
```
|
|
497
|
+
Authentication state automatically syncs across browser tabs using BroadcastChannel API and IndexedDB. When a user logs in or out in one tab, all other tabs update immediately.
|
|
364
498
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
499
|
+
## TypeScript Support
|
|
500
|
+
|
|
501
|
+
Full TypeScript definitions included:
|
|
502
|
+
|
|
503
|
+
```tsx
|
|
504
|
+
import type {
|
|
505
|
+
AuthUser,
|
|
506
|
+
AuthToken,
|
|
507
|
+
AuthResponse,
|
|
508
|
+
AuthProvider,
|
|
509
|
+
AuthUIConfig,
|
|
510
|
+
SmartlinksAuthUIProps,
|
|
511
|
+
AccountManagementProps,
|
|
512
|
+
ClaimField,
|
|
513
|
+
ClaimResult
|
|
514
|
+
} from '@smartlinks/auth-ui';
|
|
372
515
|
```
|
|
373
516
|
|
|
517
|
+
## Documentation
|
|
518
|
+
|
|
519
|
+
- **[AUTH_STATE_MANAGEMENT.md](./AUTH_STATE_MANAGEMENT.md)** - Complete guide to authentication state, callbacks, and cross-tab sync
|
|
520
|
+
- **[ACCOUNT_CACHING.md](./ACCOUNT_CACHING.md)** - Account information caching strategies and configuration
|
|
521
|
+
- **[CUSTOMIZATION_GUIDE.md](./CUSTOMIZATION_GUIDE.md)** - Detailed customization and theming guide
|
|
522
|
+
- **[SMARTLINKS_INTEGRATION.md](./SMARTLINKS_INTEGRATION.md)** - Smartlinks SDK integration details
|
|
523
|
+
|
|
374
524
|
## Troubleshooting
|
|
375
525
|
|
|
376
526
|
### Styles Not Appearing
|
|
@@ -384,14 +534,28 @@ import '@smartlinks/auth-ui/dist/index.css';
|
|
|
384
534
|
|
|
385
535
|
This import should be at the top of your app's entry point (before your component imports).
|
|
386
536
|
|
|
387
|
-
###
|
|
537
|
+
### Smartlinks SDK Not Initialized
|
|
538
|
+
|
|
539
|
+
**Problem**: `Cannot read property 'authKit' of undefined` or similar SDK errors.
|
|
540
|
+
|
|
541
|
+
**Solution**: Initialize the Smartlinks SDK before rendering components:
|
|
542
|
+
```tsx
|
|
543
|
+
import * as smartlinks from '@proveanything/smartlinks';
|
|
544
|
+
|
|
545
|
+
smartlinks.initializeApi({
|
|
546
|
+
baseUrl: 'https://smartlinks.app/api/v1',
|
|
547
|
+
proxyMode: false,
|
|
548
|
+
});
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
### Session Not Persisting
|
|
388
552
|
|
|
389
|
-
**Problem**:
|
|
553
|
+
**Problem**: Users get logged out on page refresh.
|
|
390
554
|
|
|
391
555
|
**Solution**:
|
|
392
|
-
1.
|
|
393
|
-
2.
|
|
394
|
-
3.
|
|
556
|
+
1. Ensure AuthProvider wraps your entire app
|
|
557
|
+
2. Check that IndexedDB is enabled in the browser
|
|
558
|
+
3. Verify that third-party cookies aren't blocked (affects cross-tab sync)
|
|
395
559
|
|
|
396
560
|
### TypeScript Errors
|
|
397
561
|
|
|
@@ -399,22 +563,15 @@ This import should be at the top of your app's entry point (before your componen
|
|
|
399
563
|
|
|
400
564
|
**Solution**: The package includes TypeScript definitions. Make sure:
|
|
401
565
|
```tsx
|
|
402
|
-
import type { AuthUser,
|
|
566
|
+
import type { AuthUser, AuthResponse } from '@smartlinks/auth-ui';
|
|
403
567
|
```
|
|
404
568
|
|
|
405
|
-
##
|
|
406
|
-
|
|
407
|
-
Full TypeScript definitions included:
|
|
569
|
+
## Support
|
|
408
570
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
AuthProvider,
|
|
414
|
-
AuthUIConfig,
|
|
415
|
-
SmartlinksAuthUIProps
|
|
416
|
-
} from '@smartlinks/auth-ui';
|
|
417
|
-
```
|
|
571
|
+
For issues, questions, or feature requests:
|
|
572
|
+
- GitHub Issues: [github.com/smartlinks/auth-ui](https://github.com/smartlinks/auth-ui)
|
|
573
|
+
- Documentation: [docs.smartlinks.app/auth-ui](https://docs.smartlinks.app/auth-ui)
|
|
574
|
+
- Smartlinks Platform: [smartlinks.app](https://smartlinks.app)
|
|
418
575
|
|
|
419
576
|
## License
|
|
420
577
|
|