@entro314labs/entro-auth-iris 0.0.0-stage → 1.8.0-beta.11

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/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2024 - present, Bereket Engida
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the “Software”), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ the Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,664 @@
1
+ /**
2
+ * The contract of the Iris UI auth blocks (`@/lib/auth-flow` there). Iris UI is
3
+ * copied into an app, so these types are repeated here and not imported; the
4
+ * two are compared by `pnpm check:seam`.
5
+ */
6
+ /** A single sign-on provider a block can offer. */
7
+ type AuthProvider = "Google" | "Apple" | "GitHub" | "Facebook";
8
+ /** The person a sign in resolved to. */
9
+ interface AuthAccount {
10
+ name: string;
11
+ email: string;
12
+ photo?: string;
13
+ }
14
+ /**
15
+ * A second step after the first credential was accepted. Three take a code;
16
+ * `passkey` takes none, and its handler is called with an empty one.
17
+ */
18
+ type SecondFactorMethod = "totp" | "otp" | "backup-code" | "passkey";
19
+ /**
20
+ * What a handler resolves with: an account when signed in, `secondFactor` when
21
+ * one more step is needed. Nothing from a single sign-on handler means the
22
+ * browser is leaving for the provider.
23
+ */
24
+ type AuthResult = void | {
25
+ account?: AuthAccount;
26
+ } | {
27
+ secondFactor: SecondFactorMethod[];
28
+ };
29
+ /**
30
+ * What a sign-up handler resolves with: nothing or an account when it is ready,
31
+ * `confirmEmail` when the address has to be confirmed first, by the link in the
32
+ * email or by the code it carries.
33
+ */
34
+ type SignUpResult = void | {
35
+ account?: AuthAccount;
36
+ } | {
37
+ confirmEmail: "link" | "code";
38
+ };
39
+ /** What every call of an Entro Auth client resolves with. */
40
+ interface ClientResponse<Data> {
41
+ data: Data | null;
42
+ error: {
43
+ message?: string | undefined;
44
+ statusText?: string;
45
+ } | null;
46
+ }
47
+ /** What a sign-in call answers with, as far as the handlers read it. */
48
+ interface SignInData {
49
+ user?: {
50
+ name: string;
51
+ email: string;
52
+ image?: string | null | undefined;
53
+ };
54
+ /** Set by the two-factor plugin when the account needs a second step. */
55
+ twoFactorRedirect?: boolean;
56
+ twoFactorMethods?: string[];
57
+ /** Whether the account holds backup codes to fall back on. */
58
+ twoFactorBackupCodes?: boolean;
59
+ }
60
+ /** What the Iris UI `AccountProfile` block draws. */
61
+ interface AccountProfileData {
62
+ name: string;
63
+ email: string;
64
+ photo?: string;
65
+ emailVerified: boolean;
66
+ }
67
+ /** The handler props of the block. */
68
+ interface AccountProfileHandlers {
69
+ onSave: (name: string) => Promise<void>;
70
+ onChangePhoto?: (file: File) => Promise<void>;
71
+ onRemovePhoto?: () => Promise<void>;
72
+ onChangeEmail?: (email: string) => Promise<void>;
73
+ }
74
+ /** The part of an Entro Auth client the block needs. Every client has it. */
75
+ interface AccountProfileClient {
76
+ getSession(): Promise<ClientResponse<{
77
+ user: {
78
+ name: string;
79
+ email: string;
80
+ emailVerified: boolean;
81
+ image?: string | null | undefined;
82
+ };
83
+ }>>;
84
+ updateUser(input: {
85
+ name: string;
86
+ } | {
87
+ image: string | null;
88
+ }): Promise<ClientResponse<unknown>>;
89
+ changeEmail(input: {
90
+ newEmail: string;
91
+ callbackURL?: string;
92
+ }): Promise<ClientResponse<unknown>>;
93
+ }
94
+ interface AccountProfileOptions {
95
+ /**
96
+ * Offer "Change email". The server needs `user.changeEmail.enabled`, which a
97
+ * client cannot tell, so this is yours to say.
98
+ */
99
+ changeEmail?: boolean;
100
+ /**
101
+ * Store a photo and answer the URL it is served from. The auth server keeps
102
+ * only that URL, and carries it in the session cookie, so a `data:` URL is
103
+ * refused: it would not fit. Adds "Change photo" and "Remove photo".
104
+ */
105
+ uploadPhoto?: (file: File) => Promise<string>;
106
+ /** Where the confirmation link of a new address lands. */
107
+ callbackURL?: string;
108
+ /** Called after a change, to load the data again. */
109
+ onChange?: () => void;
110
+ }
111
+ /**
112
+ * Loads what the Iris UI `AccountProfile` block draws. Throws when nobody is
113
+ * signed in.
114
+ */
115
+ export declare function loadAccountProfile(client: AccountProfileClient): Promise<AccountProfileData>;
116
+ /**
117
+ * The handler props that connect an Iris UI `AccountProfile` block to an Entro
118
+ * Auth client.
119
+ *
120
+ * @example
121
+ * ```tsx
122
+ * const data = await loadAccountProfile(authClient);
123
+ *
124
+ * <AccountProfile
125
+ * {...data}
126
+ * {...accountProfileHandlers(authClient, { changeEmail: true, onChange: reload })}
127
+ * />
128
+ * ```
129
+ */
130
+ export declare function accountProfileHandlers(client: AccountProfileClient, options?: AccountProfileOptions): AccountProfileHandlers;
131
+ /** A section of the Iris UI `AccountSecurity` block. */
132
+ type AccountSecuritySection = "password" | "two-factor" | "passkeys" | "sessions" | "connections";
133
+ /** A second step the block can turn on. */
134
+ type TwoFactorMethod = "totp" | "passkey";
135
+ /** What the block draws: one member per section that has data. */
136
+ interface AccountSecurityData {
137
+ twoFactor?: boolean;
138
+ /** Set when `twoFactorMethods` is among the options. */
139
+ twoFactorMethods?: TwoFactorMethod[];
140
+ passkeys?: {
141
+ id: string;
142
+ name: string;
143
+ detail?: string;
144
+ }[];
145
+ sessions?: {
146
+ id: string;
147
+ device: string;
148
+ detail?: string;
149
+ current?: boolean;
150
+ }[];
151
+ connections?: {
152
+ provider: AuthProvider;
153
+ account?: string;
154
+ }[];
155
+ }
156
+ /** The handler props of the block. */
157
+ interface AccountSecurityHandlers {
158
+ onChangePassword?: (current: string, next: string) => Promise<void>;
159
+ onEnableTwoFactor?: (password: string, method: TwoFactorMethod) => Promise<{
160
+ uri?: string;
161
+ backupCodes: string[];
162
+ }>;
163
+ onConfirmTwoFactor?: (code: string, method: TwoFactorMethod) => Promise<void>;
164
+ onDisableTwoFactor?: (password: string) => Promise<void>;
165
+ onAddPasskey?: () => Promise<void>;
166
+ onRemovePasskey?: (id: string) => Promise<void>;
167
+ onRevokeSession?: (id: string) => Promise<void>;
168
+ onRevokeOtherSessions?: () => Promise<void>;
169
+ onConnect?: (provider: AuthProvider) => Promise<void>;
170
+ onDisconnect?: (provider: AuthProvider) => Promise<void>;
171
+ }
172
+ interface StoredSession {
173
+ token: string;
174
+ userAgent?: string | null | undefined;
175
+ ipAddress?: string | null | undefined;
176
+ updatedAt: Date | string;
177
+ }
178
+ /**
179
+ * The part of an Entro Auth client the block needs. `twoFactorClient` adds
180
+ * `twoFactor` and `passkeyClient` adds `passkey`.
181
+ */
182
+ interface AccountSecurityClient {
183
+ getSession(): Promise<ClientResponse<{
184
+ session: {
185
+ token: string;
186
+ };
187
+ user: {
188
+ id: string;
189
+ twoFactorEnabled?: boolean | null | undefined;
190
+ };
191
+ }>>;
192
+ changePassword(input: {
193
+ currentPassword: string;
194
+ newPassword: string;
195
+ revokeOtherSessions?: boolean;
196
+ }): Promise<ClientResponse<unknown>>;
197
+ listSessions(): Promise<ClientResponse<StoredSession[]>>;
198
+ revokeSession(input: {
199
+ token: string;
200
+ }): Promise<ClientResponse<unknown>>;
201
+ revokeOtherSessions(): Promise<ClientResponse<unknown>>;
202
+ listAccounts(): Promise<ClientResponse<{
203
+ id: string;
204
+ providerId: string;
205
+ }[]>>;
206
+ linkSocial(input: {
207
+ provider: string;
208
+ callbackURL?: string;
209
+ }): Promise<ClientResponse<unknown>>;
210
+ unlinkAccount(input: {
211
+ accountId: string;
212
+ }): Promise<ClientResponse<unknown>>;
213
+ twoFactor?: {
214
+ enable(input: {
215
+ password: string;
216
+ method?: TwoFactorMethod;
217
+ }): Promise<ClientResponse<{
218
+ method?: string;
219
+ totpURI?: string;
220
+ backupCodes?: string[];
221
+ }>>;
222
+ verifyTotp(input: {
223
+ code: string;
224
+ }): Promise<ClientResponse<unknown>>;
225
+ disable(input: {
226
+ password: string;
227
+ }): Promise<ClientResponse<unknown>>;
228
+ };
229
+ passkey?: {
230
+ listUserPasskeys(): Promise<ClientResponse<{
231
+ id: string;
232
+ name?: string | undefined;
233
+ createdAt: Date | string;
234
+ }[]>>;
235
+ addPasskey(): Promise<ClientResponse<unknown> | undefined>;
236
+ deletePasskey(input: {
237
+ id: string;
238
+ }): Promise<ClientResponse<unknown>>;
239
+ verifySecondFactor(): Promise<ClientResponse<unknown>>;
240
+ };
241
+ }
242
+ interface AccountSecurityOptions {
243
+ /**
244
+ * The sections your server supports. They have to be named: a client answers
245
+ * for any plugin, installed or not, so it cannot be asked.
246
+ */
247
+ sections: AccountSecuritySection[];
248
+ /**
249
+ * The second steps an account can turn on: the authenticator app when left
250
+ * out. `"passkey"` needs `secondFactor: true` on the server's passkey plugin
251
+ * and `passkeyClient`, and is offered to an account that has a passkey.
252
+ */
253
+ twoFactorMethods?: TwoFactorMethod[];
254
+ /** Called after a change, to load the data again. */
255
+ onChange?: () => void;
256
+ /** Where the browser lands after connecting a provider. */
257
+ callbackURL?: string;
258
+ /** Sign the other devices out when the password changes. */
259
+ revokeOtherSessions?: boolean;
260
+ /** How a date reads beside a session or a passkey. */
261
+ formatDate?: (date: Date) => string;
262
+ }
263
+ /**
264
+ * Loads what the Iris UI `AccountSecurity` block draws, for the sections
265
+ * named. Call it again after a change (see `onChange`).
266
+ */
267
+ export declare function loadAccountSecurity(client: AccountSecurityClient, options: AccountSecurityOptions): Promise<AccountSecurityData>;
268
+ /**
269
+ * The handler props that connect an Iris UI `AccountSecurity` block to an
270
+ * Entro Auth client, for the sections named.
271
+ *
272
+ * @example
273
+ * ```tsx
274
+ * const options = { sections: ["password", "sessions"], onChange: reload };
275
+ * const data = await loadAccountSecurity(authClient, options);
276
+ *
277
+ * <AccountSecurity {...data} {...accountSecurityHandlers(authClient, options)} />
278
+ * ```
279
+ */
280
+ export declare function accountSecurityHandlers(client: AccountSecurityClient, options: AccountSecurityOptions): AccountSecurityHandlers;
281
+ /** What the Iris UI `OrganizationMembers` block draws. */
282
+ interface OrganizationMembersData {
283
+ members: {
284
+ id: string;
285
+ name: string;
286
+ email: string;
287
+ photo?: string;
288
+ role: string;
289
+ you?: boolean;
290
+ }[];
291
+ invitations?: {
292
+ id: string;
293
+ email: string;
294
+ role: string;
295
+ detail?: string;
296
+ }[];
297
+ }
298
+ /** The handler props of the block. */
299
+ interface OrganizationMembersHandlers {
300
+ onInvite: (email: string, role: string) => Promise<void>;
301
+ onChangeRole: (memberId: string, role: string) => Promise<void>;
302
+ onRemove: (memberId: string) => Promise<void>;
303
+ onCancelInvitation: (invitationId: string) => Promise<void>;
304
+ }
305
+ interface InOrganization {
306
+ organizationId?: string;
307
+ }
308
+ /** The part of an Entro Auth client the block needs: `organizationClient`. */
309
+ interface OrganizationMembersClient {
310
+ getSession(): Promise<ClientResponse<{
311
+ user: {
312
+ id: string;
313
+ };
314
+ }>>;
315
+ organization?: {
316
+ listMembers(input: {
317
+ query: InOrganization;
318
+ }): Promise<ClientResponse<{
319
+ members: {
320
+ id: string;
321
+ role: string;
322
+ user: {
323
+ id: string;
324
+ name: string;
325
+ email: string;
326
+ image?: string | null | undefined;
327
+ };
328
+ }[];
329
+ }>>;
330
+ listInvitations(input: {
331
+ query: InOrganization;
332
+ }): Promise<ClientResponse<{
333
+ id: string;
334
+ email: string;
335
+ role?: string | null | undefined;
336
+ status: string;
337
+ expiresAt: Date | string;
338
+ }[]>>;
339
+ inviteMember(input: InOrganization & {
340
+ email: string;
341
+ role: string | string[];
342
+ }): Promise<ClientResponse<unknown>>;
343
+ updateMemberRole(input: InOrganization & {
344
+ memberId: string;
345
+ role: string | string[];
346
+ }): Promise<ClientResponse<unknown>>;
347
+ removeMember(input: InOrganization & {
348
+ memberIdOrEmail: string;
349
+ }): Promise<ClientResponse<unknown>>;
350
+ cancelInvitation(input: {
351
+ invitationId: string;
352
+ }): Promise<ClientResponse<unknown>>;
353
+ };
354
+ }
355
+ interface OrganizationMembersOptions {
356
+ /** The organization to show. The person's active organization by default. */
357
+ organizationId?: string;
358
+ /**
359
+ * Load the pending invitations. Leave it off for people the server does not
360
+ * let read them, or the load is refused.
361
+ */
362
+ invitations?: boolean;
363
+ /** Called after a change, to load the data again. */
364
+ onChange?: () => void;
365
+ /** How the day an invitation runs out reads beside it. */
366
+ formatExpiry?: (date: Date) => string;
367
+ }
368
+ /**
369
+ * Loads what the Iris UI `OrganizationMembers` block draws. Call it again
370
+ * after a change (see `onChange`).
371
+ */
372
+ export declare function loadOrganizationMembers(client: OrganizationMembersClient, options?: OrganizationMembersOptions): Promise<OrganizationMembersData>;
373
+ /**
374
+ * The handler props that connect an Iris UI `OrganizationMembers` block to an
375
+ * Entro Auth client. Pass them to the block only for people who may manage the
376
+ * organization; the server refuses the others either way.
377
+ *
378
+ * @example
379
+ * ```tsx
380
+ * const options = { invitations: true, onChange: reload };
381
+ * const data = await loadOrganizationMembers(authClient, options);
382
+ *
383
+ * <OrganizationMembers
384
+ * {...data}
385
+ * {...organizationMembersHandlers(authClient, options)}
386
+ * />
387
+ * ```
388
+ */
389
+ export declare function organizationMembersHandlers(client: OrganizationMembersClient, options?: OrganizationMembersOptions): OrganizationMembersHandlers;
390
+ /** What the Iris UI `OrganizationSwitcher` draws. */
391
+ interface OrganizationSwitcherData {
392
+ organizations: {
393
+ id: string;
394
+ name: string;
395
+ }[];
396
+ /** The organization in use; `null` outside any organization. */
397
+ activeId: string | null;
398
+ }
399
+ /** The handler prop of the switcher. */
400
+ interface OrganizationSwitcherHandlers {
401
+ onSwitch: (id: string | null) => Promise<void>;
402
+ }
403
+ /** The part of an Entro Auth client the switcher needs: `organizationClient`. */
404
+ interface OrganizationSwitcherClient {
405
+ getSession(): Promise<ClientResponse<{
406
+ session: {
407
+ activeOrganizationId?: string | null | undefined;
408
+ };
409
+ }>>;
410
+ organization?: {
411
+ list(): Promise<ClientResponse<{
412
+ id: string;
413
+ name: string;
414
+ }[]>>;
415
+ setActive(input: {
416
+ organizationId: string | null;
417
+ }): Promise<ClientResponse<unknown>>;
418
+ };
419
+ }
420
+ /**
421
+ * Loads what the Iris UI `OrganizationSwitcher` draws: the organizations the
422
+ * person belongs to, and the one their session is in.
423
+ */
424
+ export declare function loadOrganizations(client: OrganizationSwitcherClient): Promise<OrganizationSwitcherData>;
425
+ /**
426
+ * The handler prop that connects an Iris UI `OrganizationSwitcher` to an Entro
427
+ * Auth client. Switching changes the session's active organization, which is
428
+ * what the organization endpoints act on by default.
429
+ *
430
+ * @example
431
+ * ```tsx
432
+ * const data = await loadOrganizations(authClient);
433
+ *
434
+ * <OrganizationSwitcher
435
+ * {...data}
436
+ * {...organizationSwitcherHandlers(authClient, { onChange: reload })}
437
+ * />
438
+ * ```
439
+ */
440
+ export declare function organizationSwitcherHandlers(client: OrganizationSwitcherClient, options?: {
441
+ onChange?: () => void;
442
+ }): OrganizationSwitcherHandlers;
443
+ /** The part of an Entro Auth client the handler calls. Every client has it. */
444
+ interface ResetPasswordClient {
445
+ resetPassword(input: {
446
+ newPassword: string;
447
+ token: string;
448
+ }): Promise<ClientResponse<unknown>>;
449
+ }
450
+ /** The props of the Iris UI `ResetPassword` block. */
451
+ interface ResetPasswordHandlers {
452
+ /** The link carried no token: it was used, or it ran out. */
453
+ expired: boolean;
454
+ onSubmit: (password: string) => Promise<void>;
455
+ }
456
+ /**
457
+ * The props that connect an Iris UI `ResetPassword` block to an Entro Auth
458
+ * client, on the page named as `resetPasswordURL` in `signInHandlers`. The
459
+ * server sends the browser there with a `token` query parameter, or without one
460
+ * when the link no longer works.
461
+ *
462
+ * @example
463
+ * ```tsx
464
+ * const token = new URLSearchParams(location.search).get("token");
465
+ *
466
+ * <ResetPassword
467
+ * {...resetPasswordHandlers(authClient, token)}
468
+ * onSignIn={() => router.push("/sign-in")}
469
+ * />
470
+ * ```
471
+ */
472
+ export declare function resetPasswordHandlers(client: ResetPasswordClient, token: string | null | undefined): ResetPasswordHandlers;
473
+ type Credentials<Key extends string> = Record<Key | "password", string>;
474
+ /**
475
+ * The part of an Entro Auth client the handlers call. Every client has the
476
+ * required members. Client plugins add the optional ones: `emailOTPClient` the
477
+ * emailed code, `usernameClient` usernames, `magicLinkClient` the sign-in
478
+ * link, `passkeyClient` passkeys and `twoFactorClient` the second step.
479
+ */
480
+ interface SignInClient {
481
+ emailOtp?: {
482
+ sendVerificationOtp(input: {
483
+ email: string;
484
+ type: "sign-in";
485
+ }): Promise<ClientResponse<unknown>>;
486
+ };
487
+ signIn: {
488
+ emailOtp?(input: {
489
+ email: string;
490
+ otp: string;
491
+ }): Promise<ClientResponse<SignInData>>;
492
+ email(input: Credentials<"email">): Promise<ClientResponse<SignInData>>;
493
+ username?(input: Credentials<"username">): Promise<ClientResponse<SignInData>>;
494
+ magicLink?(input: {
495
+ email: string;
496
+ callbackURL?: string;
497
+ }): Promise<ClientResponse<unknown>>;
498
+ social(input: {
499
+ provider: string;
500
+ callbackURL?: string;
501
+ }): Promise<ClientResponse<unknown>>;
502
+ passkey?(): Promise<ClientResponse<SignInData>>;
503
+ };
504
+ requestPasswordReset(input: {
505
+ email: string;
506
+ redirectTo?: string;
507
+ }): Promise<ClientResponse<unknown>>;
508
+ twoFactor?: {
509
+ verifyTotp(input: {
510
+ code: string;
511
+ }): Promise<ClientResponse<SignInData>>;
512
+ verifyOtp(input: {
513
+ code: string;
514
+ }): Promise<ClientResponse<SignInData>>;
515
+ verifyBackupCode(input: {
516
+ code: string;
517
+ }): Promise<ClientResponse<SignInData>>;
518
+ sendOtp(): Promise<ClientResponse<unknown>>;
519
+ };
520
+ /** `passkeyClient`: a passkey as the second step. */
521
+ passkey?: {
522
+ verifySecondFactor(): Promise<ClientResponse<SignInData>>;
523
+ };
524
+ signOut(): Promise<ClientResponse<unknown>>;
525
+ }
526
+ /** A way in the `SignIn` block can offer. */
527
+ type SignInMethod = "email-code" | "password" | "magic-link" | "passkey" | "social";
528
+ interface SignInHandlerOptions {
529
+ /**
530
+ * The ways in your server has set up. The block offers these and no others.
531
+ * They have to be named: a client answers for any plugin, installed or not,
532
+ * so it cannot be asked.
533
+ */
534
+ methods: SignInMethod[];
535
+ /** Where the browser lands after single sign-on or a sign-in link. */
536
+ callbackURL?: string;
537
+ /**
538
+ * Your page that takes the reset token and the new password. With the
539
+ * `password` method, adds "Forgot password?".
540
+ */
541
+ resetPasswordURL?: string;
542
+ }
543
+ /**
544
+ * The handler props of the Iris UI `SignIn` block. The block offers only the
545
+ * ways in that have a handler here.
546
+ */
547
+ interface SignInHandlers {
548
+ onSignOut: () => Promise<void>;
549
+ onSendCode?: (email: string) => Promise<void>;
550
+ onVerifyCode?: (email: string, code: string) => Promise<AuthResult>;
551
+ onPassword?: (identifier: string, password: string) => Promise<AuthResult>;
552
+ onForgotPassword?: (email: string) => Promise<void>;
553
+ onSendLink?: (email: string) => Promise<void>;
554
+ onPasskey?: () => Promise<AuthResult>;
555
+ onProvider?: (provider: AuthProvider) => Promise<AuthResult>;
556
+ onSecondFactor?: (code: string, method: SecondFactorMethod) => Promise<AuthResult>;
557
+ onSendSecondFactor?: () => Promise<void>;
558
+ }
559
+ /**
560
+ * The handler props that connect an Iris UI `SignIn` block to an Entro Auth
561
+ * client, one set per method you name. Pass the block the `providers` your
562
+ * server has configured as well.
563
+ *
564
+ * @example
565
+ * ```tsx
566
+ * const handlers = signInHandlers(authClient, {
567
+ * methods: ["password", "email-code", "social"],
568
+ * resetPasswordURL: "/reset-password",
569
+ * callbackURL: "/dashboard",
570
+ * });
571
+ *
572
+ * <SignIn
573
+ * {...handlers}
574
+ * providers={["Google", "Facebook"]}
575
+ * onSignIn={() => router.push("/dashboard")}
576
+ * />
577
+ * ```
578
+ */
579
+ export declare function signInHandlers(client: SignInClient, options: SignInHandlerOptions): SignInHandlers;
580
+ /** What the Iris UI `SignupForm` block collects. */
581
+ interface SignupDetails {
582
+ name: string;
583
+ email: string;
584
+ password: string;
585
+ productUpdates: boolean;
586
+ }
587
+ /**
588
+ * The part of an Entro Auth client the handlers call. `emailOTPClient` adds
589
+ * `emailOtp`, which confirming by code needs.
590
+ */
591
+ interface SignUpClient {
592
+ signUp: {
593
+ email(input: {
594
+ name: string;
595
+ email: string;
596
+ password: string;
597
+ } & Record<string, unknown>): Promise<ClientResponse<{
598
+ token: string | null;
599
+ }>>;
600
+ };
601
+ signIn: {
602
+ social(input: {
603
+ provider: string;
604
+ callbackURL?: string;
605
+ }): Promise<ClientResponse<unknown>>;
606
+ };
607
+ sendVerificationEmail(input: {
608
+ email: string;
609
+ callbackURL?: string;
610
+ }): Promise<ClientResponse<unknown>>;
611
+ emailOtp?: {
612
+ verifyEmail(input: {
613
+ email: string;
614
+ otp: string;
615
+ }): Promise<ClientResponse<unknown>>;
616
+ sendVerificationOtp(input: {
617
+ email: string;
618
+ type: "email-verification";
619
+ }): Promise<ClientResponse<unknown>>;
620
+ };
621
+ }
622
+ interface SignUpHandlerOptions {
623
+ /**
624
+ * How a new address is confirmed, when the server has
625
+ * `requireEmailVerification` on: by the `link` of `sendVerificationEmail`, or
626
+ * by the `code` the `emailOTP` plugin sends on sign up. Leave it out when
627
+ * accounts are ready at once.
628
+ */
629
+ confirmEmail?: "link" | "code";
630
+ /** Offer single sign-on. */
631
+ social?: boolean;
632
+ /** Where the browser lands after single sign-on or the confirmation link. */
633
+ callbackURL?: string;
634
+ /**
635
+ * The user fields your server stores beyond name, email and password, such
636
+ * as the product updates choice. Each needs a matching `user.additionalFields`
637
+ * entry on the server.
638
+ */
639
+ fields?: (details: SignupDetails) => Record<string, unknown>;
640
+ }
641
+ /** The handler props of the Iris UI `SignupForm` block. */
642
+ interface SignUpHandlers {
643
+ onSubmit: (details: SignupDetails) => Promise<SignUpResult>;
644
+ onResendConfirmation?: (email: string) => Promise<void>;
645
+ onConfirmCode?: (email: string, code: string) => Promise<void>;
646
+ onProvider?: (provider: AuthProvider) => Promise<SignUpResult>;
647
+ }
648
+ /**
649
+ * The handler props that connect an Iris UI `SignupForm` block to an Entro
650
+ * Auth client.
651
+ *
652
+ * @example
653
+ * ```tsx
654
+ * const handlers = signUpHandlers(authClient, {
655
+ * confirmEmail: "code",
656
+ * social: true,
657
+ * callbackURL: "/welcome",
658
+ * });
659
+ *
660
+ * <SignupForm {...handlers} providers={["Google", "Facebook"]} />
661
+ * ```
662
+ */
663
+ export declare function signUpHandlers(client: SignUpClient, options?: SignUpHandlerOptions): SignUpHandlers;
664
+ export type { AccountProfileClient, AccountProfileData, AccountProfileHandlers, AccountProfileOptions, AccountSecurityClient, AccountSecurityData, AccountSecurityHandlers, AccountSecurityOptions, AccountSecuritySection, AuthAccount, AuthProvider, AuthResult, OrganizationMembersClient, OrganizationMembersData, OrganizationMembersHandlers, OrganizationMembersOptions, OrganizationSwitcherClient, OrganizationSwitcherData, OrganizationSwitcherHandlers, ResetPasswordClient, ResetPasswordHandlers, SecondFactorMethod, SignInClient, SignInHandlerOptions, SignInHandlers, SignInMethod, SignUpClient, SignUpHandlerOptions, SignUpHandlers, SignUpResult, SignupDetails, TwoFactorMethod };
package/dist/index.mjs ADDED
@@ -0,0 +1,529 @@
1
+ // src/response.ts
2
+ /** The data of a client call, or its error thrown for the block to show. */
3
+ function unwrap(response) {
4
+ if (response.error) throw new Error(response.error.message || response.error.statusText || "Request failed");
5
+ return response.data;
6
+ }
7
+ /**
8
+ * Reads a sign-in answer: one more step, or the account that signed in. An
9
+ * account without a name, as a first sign in with an emailed code creates, is
10
+ * left to the block, which names it from the address.
11
+ */
12
+ function toResult(data) {
13
+ if (data?.twoFactorRedirect) {
14
+ const answered = data.twoFactorMethods ?? [];
15
+ const offered = [
16
+ "passkey",
17
+ "totp",
18
+ "otp"
19
+ ].filter((method) => answered.includes(method));
20
+ return { secondFactor: data.twoFactorBackupCodes ? [...offered, "backup-code"] : offered };
21
+ }
22
+ const user = data?.user;
23
+ if (!user?.name) return {};
24
+ return { account: {
25
+ name: user.name,
26
+ email: user.email,
27
+ ...user.image ? { photo: user.image } : {}
28
+ } };
29
+ }
30
+ // src/account-profile.ts
31
+ /**
32
+ * Loads what the Iris UI `AccountProfile` block draws. Throws when nobody is
33
+ * signed in.
34
+ */
35
+ async function loadAccountProfile(client) {
36
+ const user = unwrap(await client.getSession())?.user;
37
+ if (!user) throw new Error("Nobody is signed in.");
38
+ return {
39
+ name: user.name,
40
+ email: user.email,
41
+ emailVerified: user.emailVerified,
42
+ ...user.image ? { photo: user.image } : {}
43
+ };
44
+ }
45
+ /**
46
+ * The handler props that connect an Iris UI `AccountProfile` block to an Entro
47
+ * Auth client.
48
+ *
49
+ * @example
50
+ * ```tsx
51
+ * const data = await loadAccountProfile(authClient);
52
+ *
53
+ * <AccountProfile
54
+ * {...data}
55
+ * {...accountProfileHandlers(authClient, { changeEmail: true, onChange: reload })}
56
+ * />
57
+ * ```
58
+ */
59
+ function accountProfileHandlers(client, options = {}) {
60
+ const { callbackURL, onChange, uploadPhoto } = options;
61
+ const handlers = { async onSave(name) {
62
+ unwrap(await client.updateUser({ name }));
63
+ onChange?.();
64
+ } };
65
+ if (uploadPhoto) {
66
+ handlers.onChangePhoto = async (file) => {
67
+ const url = await uploadPhoto(file);
68
+ if (url.startsWith("data:")) throw new Error("uploadPhoto has to answer the URL of the stored photo.");
69
+ unwrap(await client.updateUser({ image: url }));
70
+ onChange?.();
71
+ };
72
+ handlers.onRemovePhoto = async () => {
73
+ unwrap(await client.updateUser({ image: null }));
74
+ onChange?.();
75
+ };
76
+ }
77
+ if (options.changeEmail) handlers.onChangeEmail = async (email) => {
78
+ unwrap(await client.changeEmail({
79
+ newEmail: email,
80
+ ...callbackURL ? { callbackURL } : {}
81
+ }));
82
+ onChange?.();
83
+ };
84
+ return handlers;
85
+ }
86
+ // src/sign-in.ts
87
+ /** The server's name for each provider the blocks can show. */
88
+ const providerIds = {
89
+ Google: "google",
90
+ Apple: "apple",
91
+ GitHub: "github",
92
+ Facebook: "facebook"
93
+ };
94
+ /** A client member a method needs, or the plugin to add when it is missing. */
95
+ function need(member, plugin) {
96
+ if (!member) throw new Error(`Add ${plugin}() to the auth client's plugins.`);
97
+ return member;
98
+ }
99
+ /**
100
+ * The handler props that connect an Iris UI `SignIn` block to an Entro Auth
101
+ * client, one set per method you name. Pass the block the `providers` your
102
+ * server has configured as well.
103
+ *
104
+ * @example
105
+ * ```tsx
106
+ * const handlers = signInHandlers(authClient, {
107
+ * methods: ["password", "email-code", "social"],
108
+ * resetPasswordURL: "/reset-password",
109
+ * callbackURL: "/dashboard",
110
+ * });
111
+ *
112
+ * <SignIn
113
+ * {...handlers}
114
+ * providers={["Google", "Facebook"]}
115
+ * onSignIn={() => router.push("/dashboard")}
116
+ * />
117
+ * ```
118
+ */
119
+ function signInHandlers(client, options) {
120
+ const { signIn } = client;
121
+ const { callbackURL, resetPasswordURL } = options;
122
+ const offers = (method) => options.methods.includes(method);
123
+ const withCallback = callbackURL ? { callbackURL } : {};
124
+ const handlers = { async onSignOut() {
125
+ unwrap(await client.signOut());
126
+ } };
127
+ if (offers("email-code")) {
128
+ const emailOtp = need(client.emailOtp, "emailOTPClient");
129
+ const verifyCode = need(signIn.emailOtp, "emailOTPClient");
130
+ handlers.onSendCode = async (email) => {
131
+ unwrap(await emailOtp.sendVerificationOtp({
132
+ email,
133
+ type: "sign-in"
134
+ }));
135
+ };
136
+ handlers.onVerifyCode = async (email, code) => toResult(unwrap(await verifyCode({
137
+ email,
138
+ otp: code
139
+ })));
140
+ }
141
+ if (offers("password")) {
142
+ handlers.onPassword = async (identifier, password) => {
143
+ if (identifier.includes("@")) return toResult(unwrap(await signIn.email({
144
+ email: identifier,
145
+ password
146
+ })));
147
+ return toResult(unwrap(await need(signIn.username, "usernameClient")({
148
+ username: identifier,
149
+ password
150
+ })));
151
+ };
152
+ handlers.onSecondFactor = async (code, method) => {
153
+ if (method === "passkey") return toResult(unwrap(await need(client.passkey, "passkeyClient").verifySecondFactor()));
154
+ const twoFactor = need(client.twoFactor, "twoFactorClient");
155
+ return toResult(unwrap(method === "totp" ? await twoFactor.verifyTotp({ code }) : method === "otp" ? await twoFactor.verifyOtp({ code }) : await twoFactor.verifyBackupCode({ code })));
156
+ };
157
+ handlers.onSendSecondFactor = async () => {
158
+ unwrap(await need(client.twoFactor, "twoFactorClient").sendOtp());
159
+ };
160
+ if (resetPasswordURL) handlers.onForgotPassword = async (email) => {
161
+ unwrap(await client.requestPasswordReset({
162
+ email,
163
+ redirectTo: resetPasswordURL
164
+ }));
165
+ };
166
+ }
167
+ if (offers("magic-link")) {
168
+ const sendLink = need(signIn.magicLink, "magicLinkClient");
169
+ handlers.onSendLink = async (email) => {
170
+ unwrap(await sendLink({
171
+ email,
172
+ ...withCallback
173
+ }));
174
+ };
175
+ }
176
+ if (offers("passkey")) {
177
+ const withPasskey = need(signIn.passkey, "passkeyClient");
178
+ handlers.onPasskey = async () => toResult(unwrap(await withPasskey()));
179
+ }
180
+ if (offers("social")) handlers.onProvider = async (provider) => {
181
+ unwrap(await signIn.social({
182
+ provider: providerIds[provider],
183
+ ...withCallback
184
+ }));
185
+ };
186
+ return handlers;
187
+ }
188
+ // src/account-security.ts
189
+ const browsers = [
190
+ [/Edg\//, "Edge"],
191
+ [/OPR\//, "Opera"],
192
+ [/Firefox\//, "Firefox"],
193
+ [/Chrome\//, "Chrome"],
194
+ [/Safari\//, "Safari"]
195
+ ];
196
+ const systems = [
197
+ [/iPhone/, "iPhone"],
198
+ [/iPad/, "iPad"],
199
+ [/Android/, "Android"],
200
+ [/Windows/, "Windows"],
201
+ [/Mac OS X/, "macOS"],
202
+ [/Linux/, "Linux"]
203
+ ];
204
+ /** "Chrome on macOS" from a user agent, as far as it can be told. */
205
+ function deviceName(userAgent) {
206
+ const find = (table) => table.find(([pattern]) => pattern.test(userAgent ?? ""))?.[1];
207
+ const browser = find(browsers);
208
+ const system = find(systems);
209
+ if (browser && system) return `${browser} on ${system}`;
210
+ return browser ?? system ?? "Unknown device";
211
+ }
212
+ const providerNames = new Map(Object.entries(providerIds).map(([name, id]) => [id, name]));
213
+ /**
214
+ * Loads what the Iris UI `AccountSecurity` block draws, for the sections
215
+ * named. Call it again after a change (see `onChange`).
216
+ */
217
+ async function loadAccountSecurity(client, options) {
218
+ const shows = (section) => options.sections.includes(section);
219
+ const formatDate = options.formatDate ?? ((date) => date.toLocaleDateString());
220
+ const data = {};
221
+ const current = unwrap(await client.getSession());
222
+ const listPasskeys = async () => unwrap(await need(client.passkey, "passkeyClient").listUserPasskeys()) ?? [];
223
+ const offersPasskey = shows("two-factor") && !!options.twoFactorMethods?.includes("passkey");
224
+ const passkeys = shows("passkeys") || offersPasskey ? await listPasskeys() : [];
225
+ if (shows("two-factor")) {
226
+ data.twoFactor = !!current?.user.twoFactorEnabled;
227
+ if (options.twoFactorMethods) data.twoFactorMethods = options.twoFactorMethods.filter((method) => method !== "passkey" || passkeys.length > 0);
228
+ }
229
+ if (shows("passkeys")) data.passkeys = passkeys.map(({ id, name, createdAt }) => ({
230
+ id,
231
+ name: name || "Passkey",
232
+ detail: formatDate(new Date(createdAt))
233
+ }));
234
+ if (shows("sessions")) data.sessions = (unwrap(await client.listSessions()) ?? []).map((session) => ({
235
+ id: session.token,
236
+ device: deviceName(session.userAgent),
237
+ detail: [session.ipAddress, formatDate(new Date(session.updatedAt))].filter(Boolean).join(" · "),
238
+ current: session.token === current?.session.token
239
+ }));
240
+ if (shows("connections")) data.connections = (unwrap(await client.listAccounts()) ?? []).flatMap(({ providerId }) => {
241
+ const provider = providerNames.get(providerId);
242
+ return provider ? [{ provider }] : [];
243
+ });
244
+ return data;
245
+ }
246
+ /**
247
+ * The handler props that connect an Iris UI `AccountSecurity` block to an
248
+ * Entro Auth client, for the sections named.
249
+ *
250
+ * @example
251
+ * ```tsx
252
+ * const options = { sections: ["password", "sessions"], onChange: reload };
253
+ * const data = await loadAccountSecurity(authClient, options);
254
+ *
255
+ * <AccountSecurity {...data} {...accountSecurityHandlers(authClient, options)} />
256
+ * ```
257
+ */
258
+ function accountSecurityHandlers(client, options) {
259
+ const shows = (section) => options.sections.includes(section);
260
+ const { callbackURL, onChange } = options;
261
+ /** Runs a client call, throws its error, then asks for the data again. */
262
+ async function change(call) {
263
+ const response = await call;
264
+ const data = response ? unwrap(response) : null;
265
+ onChange?.();
266
+ return data;
267
+ }
268
+ const handlers = {};
269
+ if (shows("password")) handlers.onChangePassword = async (current, next) => {
270
+ await change(client.changePassword({
271
+ currentPassword: current,
272
+ newPassword: next,
273
+ ...options.revokeOtherSessions ? { revokeOtherSessions: true } : {}
274
+ }));
275
+ };
276
+ if (shows("two-factor")) {
277
+ const twoFactor = need(client.twoFactor, "twoFactorClient");
278
+ handlers.onEnableTwoFactor = async (password, method) => {
279
+ if (method === "passkey") return { backupCodes: unwrap(await twoFactor.enable({
280
+ password,
281
+ method
282
+ }))?.backupCodes ?? [] };
283
+ const setup = unwrap(await twoFactor.enable({ password }));
284
+ if (!setup?.totpURI) throw new Error("The server has no authenticator app setup.");
285
+ return {
286
+ uri: setup.totpURI,
287
+ backupCodes: setup.backupCodes ?? []
288
+ };
289
+ };
290
+ handlers.onConfirmTwoFactor = async (code, method) => {
291
+ if (method === "passkey") {
292
+ await change(need(client.passkey, "passkeyClient").verifySecondFactor());
293
+ return;
294
+ }
295
+ await change(twoFactor.verifyTotp({ code }));
296
+ };
297
+ handlers.onDisableTwoFactor = async (password) => {
298
+ await change(twoFactor.disable({ password }));
299
+ };
300
+ }
301
+ if (shows("passkeys")) {
302
+ const passkey = need(client.passkey, "passkeyClient");
303
+ handlers.onAddPasskey = async () => {
304
+ await change(passkey.addPasskey());
305
+ };
306
+ handlers.onRemovePasskey = async (id) => {
307
+ await change(passkey.deletePasskey({ id }));
308
+ };
309
+ }
310
+ if (shows("sessions")) {
311
+ handlers.onRevokeSession = async (id) => {
312
+ await change(client.revokeSession({ token: id }));
313
+ };
314
+ handlers.onRevokeOtherSessions = async () => {
315
+ await change(client.revokeOtherSessions());
316
+ };
317
+ }
318
+ if (shows("connections")) {
319
+ handlers.onConnect = async (provider) => {
320
+ unwrap(await client.linkSocial({
321
+ provider: providerIds[provider],
322
+ ...callbackURL ? { callbackURL } : {}
323
+ }));
324
+ };
325
+ handlers.onDisconnect = async (provider) => {
326
+ const account = (unwrap(await client.listAccounts()) ?? []).find(({ providerId }) => providerId === providerIds[provider]);
327
+ if (!account) throw new Error(`${provider} is not connected.`);
328
+ await change(client.unlinkAccount({ accountId: account.id }));
329
+ };
330
+ }
331
+ return handlers;
332
+ }
333
+ // src/organization-members.ts
334
+ /**
335
+ * Loads what the Iris UI `OrganizationMembers` block draws. Call it again
336
+ * after a change (see `onChange`).
337
+ */
338
+ async function loadOrganizationMembers(client, options = {}) {
339
+ const organization = need(client.organization, "organizationClient");
340
+ const query = options.organizationId ? { organizationId: options.organizationId } : {};
341
+ const formatExpiry = options.formatExpiry ?? ((date) => `Expires ${date.toLocaleDateString()}`);
342
+ const viewer = unwrap(await client.getSession())?.user.id;
343
+ const data = { members: (unwrap(await organization.listMembers({ query }))?.members ?? []).map(({ id, role, user }) => ({
344
+ id,
345
+ name: user.name,
346
+ email: user.email,
347
+ role,
348
+ ...user.image ? { photo: user.image } : {},
349
+ ...user.id === viewer ? { you: true } : {}
350
+ })) };
351
+ if (options.invitations) data.invitations = (unwrap(await organization.listInvitations({ query })) ?? []).filter((invitation) => invitation.status === "pending").map(({ id, email, role, expiresAt }) => ({
352
+ id,
353
+ email,
354
+ role: role ?? "member",
355
+ detail: formatExpiry(new Date(expiresAt))
356
+ }));
357
+ return data;
358
+ }
359
+ /**
360
+ * The handler props that connect an Iris UI `OrganizationMembers` block to an
361
+ * Entro Auth client. Pass them to the block only for people who may manage the
362
+ * organization; the server refuses the others either way.
363
+ *
364
+ * @example
365
+ * ```tsx
366
+ * const options = { invitations: true, onChange: reload };
367
+ * const data = await loadOrganizationMembers(authClient, options);
368
+ *
369
+ * <OrganizationMembers
370
+ * {...data}
371
+ * {...organizationMembersHandlers(authClient, options)}
372
+ * />
373
+ * ```
374
+ */
375
+ function organizationMembersHandlers(client, options = {}) {
376
+ const organization = need(client.organization, "organizationClient");
377
+ const inOrganization = options.organizationId ? { organizationId: options.organizationId } : {};
378
+ /** Runs a client call, throws its error, then asks for the data again. */
379
+ async function change(call) {
380
+ unwrap(await call);
381
+ options.onChange?.();
382
+ }
383
+ return {
384
+ onInvite: (email, role) => change(organization.inviteMember({
385
+ ...inOrganization,
386
+ email,
387
+ role
388
+ })),
389
+ onChangeRole: (memberId, role) => change(organization.updateMemberRole({
390
+ ...inOrganization,
391
+ memberId,
392
+ role
393
+ })),
394
+ onRemove: (memberId) => change(organization.removeMember({
395
+ ...inOrganization,
396
+ memberIdOrEmail: memberId
397
+ })),
398
+ onCancelInvitation: (invitationId) => change(organization.cancelInvitation({ invitationId }))
399
+ };
400
+ }
401
+ // src/organization-switcher.ts
402
+ /**
403
+ * Loads what the Iris UI `OrganizationSwitcher` draws: the organizations the
404
+ * person belongs to, and the one their session is in.
405
+ */
406
+ async function loadOrganizations(client) {
407
+ const organization = need(client.organization, "organizationClient");
408
+ const session = unwrap(await client.getSession())?.session;
409
+ return {
410
+ organizations: (unwrap(await organization.list()) ?? []).map(({ id, name }) => ({
411
+ id,
412
+ name
413
+ })),
414
+ activeId: session?.activeOrganizationId ?? null
415
+ };
416
+ }
417
+ /**
418
+ * The handler prop that connects an Iris UI `OrganizationSwitcher` to an Entro
419
+ * Auth client. Switching changes the session's active organization, which is
420
+ * what the organization endpoints act on by default.
421
+ *
422
+ * @example
423
+ * ```tsx
424
+ * const data = await loadOrganizations(authClient);
425
+ *
426
+ * <OrganizationSwitcher
427
+ * {...data}
428
+ * {...organizationSwitcherHandlers(authClient, { onChange: reload })}
429
+ * />
430
+ * ```
431
+ */
432
+ function organizationSwitcherHandlers(client, options = {}) {
433
+ const organization = need(client.organization, "organizationClient");
434
+ return { async onSwitch(id) {
435
+ try {
436
+ unwrap(await organization.setActive({ organizationId: id }));
437
+ } finally {
438
+ options.onChange?.();
439
+ }
440
+ } };
441
+ }
442
+ // src/reset-password.ts
443
+ /**
444
+ * The props that connect an Iris UI `ResetPassword` block to an Entro Auth
445
+ * client, on the page named as `resetPasswordURL` in `signInHandlers`. The
446
+ * server sends the browser there with a `token` query parameter, or without one
447
+ * when the link no longer works.
448
+ *
449
+ * @example
450
+ * ```tsx
451
+ * const token = new URLSearchParams(location.search).get("token");
452
+ *
453
+ * <ResetPassword
454
+ * {...resetPasswordHandlers(authClient, token)}
455
+ * onSignIn={() => router.push("/sign-in")}
456
+ * />
457
+ * ```
458
+ */
459
+ function resetPasswordHandlers(client, token) {
460
+ return {
461
+ expired: !token,
462
+ async onSubmit(password) {
463
+ unwrap(await client.resetPassword({
464
+ newPassword: password,
465
+ token: token ?? ""
466
+ }));
467
+ }
468
+ };
469
+ }
470
+ // src/sign-up.ts
471
+ /**
472
+ * The handler props that connect an Iris UI `SignupForm` block to an Entro
473
+ * Auth client.
474
+ *
475
+ * @example
476
+ * ```tsx
477
+ * const handlers = signUpHandlers(authClient, {
478
+ * confirmEmail: "code",
479
+ * social: true,
480
+ * callbackURL: "/welcome",
481
+ * });
482
+ *
483
+ * <SignupForm {...handlers} providers={["Google", "Facebook"]} />
484
+ * ```
485
+ */
486
+ function signUpHandlers(client, options = {}) {
487
+ const { confirmEmail, callbackURL } = options;
488
+ const withCallback = callbackURL ? { callbackURL } : {};
489
+ const handlers = { async onSubmit(details) {
490
+ const { name, email, password } = details;
491
+ const created = unwrap(await client.signUp.email({
492
+ ...options.fields?.(details),
493
+ name,
494
+ email,
495
+ password,
496
+ ...withCallback
497
+ }));
498
+ return confirmEmail && !created?.token ? { confirmEmail } : {};
499
+ } };
500
+ if (confirmEmail === "link") handlers.onResendConfirmation = async (email) => {
501
+ unwrap(await client.sendVerificationEmail({
502
+ email,
503
+ ...withCallback
504
+ }));
505
+ };
506
+ if (confirmEmail === "code") {
507
+ const emailOtp = need(client.emailOtp, "emailOTPClient");
508
+ handlers.onConfirmCode = async (email, code) => {
509
+ unwrap(await emailOtp.verifyEmail({
510
+ email,
511
+ otp: code
512
+ }));
513
+ };
514
+ handlers.onResendConfirmation = async (email) => {
515
+ unwrap(await emailOtp.sendVerificationOtp({
516
+ email,
517
+ type: "email-verification"
518
+ }));
519
+ };
520
+ }
521
+ if (options.social) handlers.onProvider = async (provider) => {
522
+ unwrap(await client.signIn.social({
523
+ provider: providerIds[provider],
524
+ ...withCallback
525
+ }));
526
+ };
527
+ return handlers;
528
+ }
529
+ export { accountProfileHandlers, accountSecurityHandlers, loadAccountProfile, loadAccountSecurity, loadOrganizationMembers, loadOrganizations, organizationMembersHandlers, organizationSwitcherHandlers, resetPasswordHandlers, signInHandlers, signUpHandlers };
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@entro314labs/entro-auth-iris",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.8.0-beta.11",
4
+ "description": "Handlers that connect an Entro Auth client to the Iris UI sign-in blocks",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/entro314-labs/entro-auth.git",
10
+ "directory": "packages/iris"
11
+ },
12
+ "keywords": [
13
+ "auth",
14
+ "iris-ui",
15
+ "sign-in",
16
+ "react",
17
+ "typescript",
18
+ "entro-auth"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "sideEffects": false,
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "main": "./dist/index.mjs",
28
+ "module": "./dist/index.mjs",
29
+ "types": "./dist/index.d.mts",
30
+ "exports": {
31
+ ".": {
32
+ "dev-source": "./src/index.ts",
33
+ "types": "./dist/index.d.mts",
34
+ "default": "./dist/index.mjs"
35
+ }
36
+ },
37
+ "devDependencies": {
38
+ "@better-auth/utils": "0.5.1",
39
+ "@entro314labs/entro-auth-core": "1.8.0-beta.11",
40
+ "@entro314labs/entro-auth-passkey": "1.8.0-beta.11",
41
+ "@entro314labs/entro-auth": "1.8.0-beta.11",
42
+ "happy-dom": "^21.0.4",
43
+ "tsdown": "0.23.1",
44
+ "typescript": "^6.0.3"
45
+ },
46
+ "scripts": {
47
+ "build": "tsdown",
48
+ "dev": "tsdown --watch",
49
+ "lint:package": "publint run --strict --pack false",
50
+ "lint:types": "attw --profile esm-only --pack .",
51
+ "typecheck": "tsc --noEmit",
52
+ "test": "vitest",
53
+ "coverage": "vitest run --coverage --coverage.provider=istanbul",
54
+ "check:seam": "tsc -p seam && vitest run --config seam/vitest.config.ts"
55
+ }
6
56
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.