-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCorbadoConnectDemo.tsx
More file actions
448 lines (435 loc) · 15.8 KB
/
CorbadoConnectDemo.tsx
File metadata and controls
448 lines (435 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
import type { CorbadoConnectDemoConfig } from '@corbado/types';
import type { Passkey } from '@corbado/web-core';
import type { FC } from 'react';
import React from 'react';
import AppendAfterError from './append/append-init/AppendAfterError';
import AppendInitLoaded2 from './append/append-init/AppendInitLoaded2';
import AppendInitLoading from './append/append-init/AppendInitLoading';
import AppendSuccessScreen from './append/AppendSuccessScreen';
import LoginErrorHard from './login/base/LoginErrorHard';
import LoginErrorSoft from './login/base/LoginErrorSoft';
import LoginHybrid from './login/base/LoginHybrid';
import LoginInitLoaded from './login/base/LoginInitLoaded';
import LoginInitLoading from './login/base/LoginInitLoading';
import LoginOneTap from './login/base/LoginOneTap';
import AlreadyExistingModal from './passkeyList/AlreadyExistingModal';
import DeleteModal from './passkeyList/DeleteModal';
import PasskeyAppendNotSupportedLightModal from './passkeyList/PasskeyAppendNotSupportedLightModal';
import PasskeyAppendNotSupportedModal from './passkeyList/PasskeyAppendNotSupportedModal';
import PasskeyList, { PasskeyListState } from './passkeyList/PasskeyList';
const getListOfPasskeys = () => {
const out: Passkey[] = [
{
id: '1',
credentialID: '123',
attestationType: 'attestationType',
transport: [],
backupEligible: true,
backupState: true,
authenticatorAAGUID: 'authenticatorAAGUID',
sourceOS: 'Windows 10',
sourceBrowser: 'Chrome',
lastUsed: '2024-10-03 14:45:57',
created: '2024-10-03 14:45:57',
status: '' as any,
aaguidDetails: {
iconDark: 'https://cdn.cloud.corbado.io/aaguidIcons/01020304-0506-0708-0102-030405060708/dark.png',
iconLight: 'https://cdn.cloud.corbado.io/aaguidIcons/01020304-0506-0708-0102-030405060708/light.png',
name: 'Passkey',
},
createdMs: 1735689600000,
lastUsedMs: 1735689600000,
tags: [],
},
{
aaguidDetails: {
iconDark: 'https://cdn.cloud.corbado.io/aaguidIcons/2fc0579f-8113-47ea-b116-bb5a8db9202a/dark.png',
iconLight: 'https://cdn.cloud.corbado.io/aaguidIcons/2fc0579f-8113-47ea-b116-bb5a8db9202a/light.png',
name: 'YubiKey 5 Series with NFC',
},
attestationType: 'packed',
authenticatorAAGUID: '2fc0579f-8113-47ea-b116-bb5a8db9202a',
backupEligible: false,
backupState: false,
created: '2024-10-03 14:45:57',
credentialID: 'KISojPMjtXUArj+vYNxlDKcbZe8pu6oODu8kIPp0H9DxbUYiHkXp5kRduwE2bD9i',
id: 'cre-10462634909848370484',
lastUsed: '2024-10-03 14:45:57',
sourceBrowser: 'Chrome',
sourceOS: 'macOS',
status: 'active',
transport: ['nfc', 'usb'],
createdMs: 1735689600000,
lastUsedMs: 1735689600000,
tags: [],
},
{
aaguidDetails: {
iconDark: 'https://cdn.cloud.corbado.io/aaguidIcons/fbfc3007-154e-4ecc-8c0b-6e020557d7bd/dark.svg',
iconLight: 'https://cdn.cloud.corbado.io/aaguidIcons/fbfc3007-154e-4ecc-8c0b-6e020557d7bd/light.svg',
name: 'iCloud Keychain',
},
attestationType: 'none',
authenticatorAAGUID: 'fbfc3007-154e-4ecc-8c0b-6e020557d7bd',
backupEligible: true,
backupState: true,
created: '2024-08-30 19:28:48',
credentialID: 'GseKHMtnpVgWqUf0K/H+wUR1fQw=',
id: 'cre-13671099221995212892',
lastUsed: '2024-10-24 03:26:36',
sourceBrowser: 'Chrome',
sourceOS: 'macOS',
status: 'active',
transport: ['hybrid', 'internal'],
createdMs: 1735689600000,
lastUsedMs: 1735689600000,
tags: [],
},
];
return out;
};
type Element = {
headline: string;
description?: string;
reactElement: React.ReactElement;
};
const CorbadoConnectDemo: FC<CorbadoConnectDemoConfig> = _ => {
const [showDescriptions, setShowDescriptions] = React.useState(false);
const handleChange = () => {
setShowDescriptions(!showDescriptions);
};
const passkeyListElements: Element[] = [
{
headline: 'Initial loading state',
description: 'This screen is shown to the user when the passkey list component is initializing.',
reactElement: (
<PasskeyList
passkeys={[]}
onDeleteClick={passkey => console.log('Delete click', passkey)}
state={PasskeyListState.Loading}
onAppendClick={() => console.log('Append click')}
appendLoading={false}
hardErrorMessage={null}
/>
),
},
{
headline: 'Loading failed state',
description: 'This screen is shown to the user when the passkey list component failed to initialize.',
reactElement: (
<PasskeyList
passkeys={[]}
onDeleteClick={passkey => console.log('Delete click', passkey)}
state={PasskeyListState.LoadingFailed}
onAppendClick={() => console.log('Append click')}
appendLoading={false}
hardErrorMessage={null}
/>
),
},
{
headline: 'Loaded state (user has no passkeys)',
description:
'This screen is shown to the user when the passkey list component is initialized and the user has no passkeys.',
reactElement: (
<PasskeyList
passkeys={[]}
onDeleteClick={passkey => console.log('Delete click', passkey)}
state={PasskeyListState.Loaded}
onAppendClick={() => console.log('Append click')}
appendLoading={false}
hardErrorMessage={null}
/>
),
},
{
headline: 'Loaded state (user has passkeys)',
description:
'This screen is shown to the user when the passkey list component is initialized and the user has at least one passkey.',
reactElement: (
<PasskeyList
passkeys={getListOfPasskeys()}
onDeleteClick={passkey => console.log('Delete click', passkey)}
state={PasskeyListState.Loaded}
onAppendClick={() => console.log('Append click')}
appendLoading={false}
hardErrorMessage={null}
/>
),
},
{
headline: 'Loaded state with error',
description:
'This screen is shown to the user when there was an error after the user tried to append or delete a passkey.',
reactElement: (
<PasskeyList
passkeys={getListOfPasskeys()}
onDeleteClick={passkey => console.log('Delete click', passkey)}
state={PasskeyListState.Loaded}
onAppendClick={() => console.log('Append click')}
appendLoading={false}
hardErrorMessage='Passkey operation was cancelled or timed out. Please try again.'
/>
),
},
];
const passkeyListModals: Element[] = [
{
headline: 'Passkey delete modal',
description:
'This modal is shown to the user when they want to delete a passkey. Only when a user confirms the deletion in this modal, the passkey will be deleted.',
reactElement: (
<DeleteModal
passkey={getListOfPasskeys()[0]}
onDeleteClick={async _ => Promise.resolve()}
hide={() => console.log('hide')}
/>
),
},
{
headline: 'Passkey already exists modal',
description:
'This modal is shown to the user when they try to append a passkey but there is already an existing passkey available on that device.',
reactElement: <AlreadyExistingModal hide={() => console.log('hide')} />,
},
{
headline: 'Passkey append not supported modal',
description:
'This modal is shown to the user when they try to append a passkey but the operation is not supported by their device (e.g. because it is too old).',
reactElement: <PasskeyAppendNotSupportedModal hide={() => console.log('hide')} />,
},
{
headline: 'Passkey append not supported light modal',
description:
'This modal is shown to the user when they try to append a passkey but the operation is not supported by their current browser (another browser on the same device might support it though).',
reactElement: <PasskeyAppendNotSupportedLightModal hide={() => console.log('hide')} />,
},
];
const append: Element[] = [
{
headline: 'Append loading',
description: 'This screen is shown to the user when the append component is initializing.',
reactElement: <AppendInitLoading />,
},
{
headline: 'Append screen initial',
description: 'This screen is shown to the user when the append process is not yet started.',
reactElement: (
<AppendInitLoaded2
errorMessage={undefined}
appendLoading={false}
handleShowBenefits={() => console.log('Show benefits')}
handleSubmit={() => console.log('Submit')}
handleSkip={() => console.log('Skip')}
/>
),
},
{
headline: 'Append screen with error',
description:
'This screen is shown to the user when an error occurs during the append process. The user can retry the append.',
reactElement: (
<AppendInitLoaded2
errorMessage={'Passkey operation was cancelled or timed out. Please try again.'}
appendLoading={false}
handleShowBenefits={() => console.log('Show benefits')}
handleSubmit={() => console.log('Submit')}
handleSkip={() => console.log('Skip')}
/>
),
},
{
headline: 'Append successful',
description: 'This screen is shown to the user when the append process was successful.',
reactElement: (
<AppendSuccessScreen
aaguidName='iCloud Keychain'
aaguidIcon='https://cdn.cloud.corbado.io/aaguidIcons/fbfc3007-154e-4ecc-8c0b-6e020557d7bd/light.svg'
/>
),
},
{
headline: 'Append screen after error',
description: 'This screen is shown to the user after having issues with passkeys.',
reactElement: (
<AppendAfterError
errorMessage={''}
appendLoading={false}
handleSubmit={() => console.log('Submit')}
handleSkip={() => console.log('Skip')}
/>
),
},
];
const login: Element[] = [
{
headline: 'Login screen loading',
description: 'This screen is shown to the user when the login component is initializing.',
reactElement: <LoginInitLoading />,
},
{
headline: 'Login screen initial',
description:
'This screen is shown to the user when the user is not logged in and the login process is not yet started.',
reactElement: (
<LoginInitLoaded
isLoading={false}
error={undefined}
onSignupClick={() => console.log('Signup click')}
autoComplete={'email'}
handleSubmit={() => console.log('Submit')}
handleIdentifierUpdate={() => console.log('')}
/>
),
},
{
headline: 'Login screen error (user does not exist)',
description: 'This screen is shown to the user when the user does not exist in the system.',
reactElement: (
<LoginInitLoaded
isLoading={false}
error={'There is no account registered with this email.'}
onSignupClick={() => console.log('Signup click')}
autoComplete={'email'}
handleSubmit={() => console.log('Submit')}
handleIdentifierUpdate={() => console.log('')}
/>
),
},
{
headline: 'Login soft error',
description:
'This screen is shown to the user when a passkey operation has been cancelled during login or when another client-side error occurs. The user sees this error only once. Subsequent errors will be shown as hard errors.',
reactElement: (
<LoginErrorSoft
loading={false}
handleSubmit={() => console.log('Submit')}
handleExplicitFallback={() => console.log('Fallback')}
/>
),
},
{
headline: 'Login hard error',
description:
'This screen is shown to the user when a passkey operation has been cancelled during login. Usually the user is first shown the soft error screen.',
reactElement: (
<LoginErrorHard
loading={false}
handleSubmit={() => console.log('Submit')}
handleExplicitFallback={() => console.log('Fallback')}
handleNeedHelp={() => console.log('Need help')}
/>
),
},
{
headline: 'Login screen hybrid',
description:
'This screen is shown to a user during the login process if there is a high chance that the upcoming passkey operation will be CDA.',
reactElement: (
<LoginHybrid
loading={false}
handleSubmit={() => console.log('Submit')}
handleFallback={() => console.log('Fallback')}
/>
),
},
{
headline: 'Login screen with OneTap button',
description:
'This screen is shown to the user when a passkey is available on the current device. The user thus does not have to type in their email address.',
reactElement: (
<LoginOneTap
loading={false}
currentIdentifier='igor.gjorgjioski@vicroads.com.au'
handleSubmit={() => console.log('Submit')}
handleSwitch={() => console.log()}
/>
),
},
];
return (
<>
<div className='demo-controls'>
<label className='demo-controls-item'>
<input
type='checkbox'
checked={showDescriptions}
onChange={handleChange}
/>
Show descriptions for components (optional)
</label>
</div>
{passkeyListElements.map((element, index) => (
<div
className='cb-demo-screen-container'
key={index}
>
<div className={`cb-demo-screen ${showDescriptions && 'cb-demo-screen-box'}`}>
<div className='cb-connect-container cb-connect-passkey-list'>{element.reactElement}</div>
</div>
{showDescriptions && (
<Description
headline={element.headline}
description={element.description}
/>
)}
</div>
))}
{passkeyListModals.map((element, index) => (
<div
className='cb-connect light'
key={index}
>
<div className='cb-connect-custom-style'>
<div className='cb-modal-outer-content'>{element.reactElement}</div>
</div>
{showDescriptions && (
<Description
headline={element.headline}
description={element.description}
/>
)}
</div>
))}
{append.map((element, index) => (
<div
className='cb-demo-screen-container'
key={index}
>
<div className={`cb-demo-screen ${showDescriptions && 'cb-demo-screen-box'}`}>
<div className='cb-connect-container cb-connect-append'>{element.reactElement}</div>
</div>
{showDescriptions && (
<Description
headline={element.headline}
description={element.description}
/>
)}
</div>
))}
{login.map((element, index) => (
<div
className='cb-demo-screen-container'
key={index}
>
<div className={`cb-demo-screen ${showDescriptions && 'cb-demo-screen-box'}`}>
<div className='cb-connect-container cb-connect-login'>{element.reactElement}</div>
</div>
{showDescriptions && (
<Description
headline={element.headline}
description={element.description}
/>
)}
</div>
))}
</>
);
};
const Description = ({ headline, description }: { headline: string; description?: string }) => (
<div className='description'>
<div className='description-headline'>{headline}</div>
<div className='description-content'>{description}</div>
</div>
);
export default CorbadoConnectDemo;