@protobase/server 0.21.12 → 0.22.1

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.
Files changed (28) hide show
  1. package/dist/better-auth/auth-mail/invitation-email.js +23 -27
  2. package/dist/better-auth/create-auth.d.ts +462 -24
  3. package/dist/better-auth/create-auth.js +12 -1
  4. package/dist/better-auth/invitations/account-from-invitation.js +50 -0
  5. package/dist/better-auth/invitations/invitation-endpoints.js +102 -0
  6. package/dist/better-auth/invitations/invitation-link-hook.js +34 -0
  7. package/dist/better-auth/invitations/invitation-of-token.js +24 -0
  8. package/dist/better-auth/{organizations → invitations}/invitation-token.js +7 -2
  9. package/dist/better-auth/last-admin-guard.js +62 -0
  10. package/dist/better-auth/last-admin.js +18 -0
  11. package/dist/better-auth/organizations/accept-invitation.js +4 -8
  12. package/dist/better-auth/organizations/invitation-endpoints.js +17 -114
  13. package/dist/better-auth/organizations/member-endpoints.js +36 -19
  14. package/dist/better-auth/organizations/options.js +2 -1
  15. package/dist/better-auth/organizations/organization-plugin.js +1 -1
  16. package/dist/better-auth/organizations/protobase-plugin.js +7 -9
  17. package/dist/better-auth/organizations/role-definitions.js +5 -4
  18. package/dist/better-auth/passkey-plugin.js +1 -1
  19. package/dist/better-auth/roles/role-labels.js +14 -0
  20. package/dist/better-auth/sign-up/sign-up-plugin.js +1 -1
  21. package/dist/better-auth/status-route.js +3 -8
  22. package/dist/better-auth/users/app-invitation-store.js +62 -0
  23. package/dist/better-auth/users/user-endpoints.js +79 -0
  24. package/dist/better-auth/users/users-plugin.js +22 -0
  25. package/dist/better-auth/users.js +1 -2
  26. package/dist/check-views.js +5 -3
  27. package/dist/index.js +1 -1
  28. package/package.json +4 -4
@@ -3,35 +3,31 @@ import { AuthEmailLayout, EmailButton, EmailNote } from "./auth-email-layout.js"
3
3
  import { Text } from "react-email";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  //#region src/better-auth/auth-mail/invitation-email.tsx
6
- const InvitationEmail = ({ app, inviter, organization, url, expiresAt }) => /* @__PURE__ */ jsxs(AuthEmailLayout, {
7
- app,
8
- preview: `${inviter} invites you to join ${organization}`,
9
- heading: `Join ${organization}`,
10
- children: [
11
- /* @__PURE__ */ jsxs(Text, { children: [
12
- inviter,
13
- " invites you to join ",
14
- organization,
15
- " on ",
16
- app.name,
17
- ". To accept, open this link:"
18
- ] }),
19
- /* @__PURE__ */ jsx(EmailButton, {
20
- href: url,
21
- children: "Accept the invitation"
22
- }),
23
- /* @__PURE__ */ jsxs(Text, { children: [
24
- "The link works until ",
25
- expiresAt.toUTCString(),
26
- "."
27
- ] }),
28
- /* @__PURE__ */ jsx(EmailNote, { children: "If you do not want to join, ignore this email: nothing happens without you." })
29
- ]
30
- });
31
- /** The invitation email: who invites whom to which organization, the link, and until when it works. */
6
+ const InvitationEmail = ({ app, inviter, organization, url, expiresAt }) => {
7
+ const target = organization ?? app.name;
8
+ return /* @__PURE__ */ jsxs(AuthEmailLayout, {
9
+ app,
10
+ preview: `${inviter} invites you to join ${target}`,
11
+ heading: `Join ${target}`,
12
+ children: [
13
+ /* @__PURE__ */ jsxs(Text, { children: [organization ? `${inviter} invites you to join ${organization} on ${app.name}.` : `${inviter} invites you to join ${app.name}.`, " To accept, open this link:"] }),
14
+ /* @__PURE__ */ jsx(EmailButton, {
15
+ href: url,
16
+ children: "Accept the invitation"
17
+ }),
18
+ /* @__PURE__ */ jsxs(Text, { children: [
19
+ "The link works until ",
20
+ expiresAt.toUTCString(),
21
+ "."
22
+ ] }),
23
+ /* @__PURE__ */ jsx(EmailNote, { children: "If you do not want to join, ignore this email: nothing happens without you." })
24
+ ]
25
+ });
26
+ };
27
+ /** The invitation email: who invites whom to which organization, or to the app, the link, and until when it works. */
32
28
  const invitationEmail = defineEmail({
33
29
  name: "invitation",
34
- subject: ({ organization, app }) => `Join ${organization} on ${app.name}`,
30
+ subject: ({ organization, app }) => organization ? `Join ${organization} on ${app.name}` : `Join ${app.name}`,
35
31
  component: InvitationEmail
36
32
  });
37
33
  //#endregion
@@ -2331,10 +2331,8 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
2331
2331
  userId: string;
2332
2332
  expiresAt: Date;
2333
2333
  token: string;
2334
- ipAddress?
2335
- /** The app's name it signs in and mails as: `appName`, else `PROTOBASE_APP_NAME`, else `Protobase`. */
2336
- /** The app's name it signs in and mails as: `appName`, else `PROTOBASE_APP_NAME`, else `Protobase`. */ : string | null | undefined;
2337
- userAgent?: string | null | undefined;
2334
+ ipAddress?: string | null | undefined;
2335
+ userAgent? /** Every origin the app is served on, `baseURL`'s first. */ : string | null | undefined;
2338
2336
  };
2339
2337
  user: Record<string, any> & {
2340
2338
  id: string;
@@ -4718,6 +4716,14 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
4718
4716
  handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
4719
4717
  }[];
4720
4718
  };
4719
+ } | {
4720
+ id: "protobase-last-admin";
4721
+ hooks: {
4722
+ before: {
4723
+ matcher: (ctx: import("better-auth").HookEndpointContext) => boolean;
4724
+ handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
4725
+ }[];
4726
+ };
4721
4727
  } | import("better-auth/plugins").DefaultOrganizationPlugin<{
4722
4728
  organizationHooks: {
4723
4729
  beforeCreateOrganization?: (data: {
@@ -5149,6 +5155,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
5149
5155
  }>>[];
5150
5156
  query: import("zod").ZodObject<{
5151
5157
  query: import("zod").ZodDefault<import("zod").ZodString>;
5158
+ offset: import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
5152
5159
  }, import("zod/v4/core").$strip>;
5153
5160
  }, {
5154
5161
  organizations: {
@@ -5156,25 +5163,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
5156
5163
  name: string;
5157
5164
  slug: string;
5158
5165
  }[];
5159
- }>;
5160
- getInvitation: import("better-auth").StrictEndpoint<"/invitation", {
5161
- method: "GET";
5162
- query: import("zod").ZodObject<{
5163
- token: import("zod").ZodString;
5164
- }, import("zod/v4/core").$strip>;
5165
- }, {
5166
- organization: {
5167
- id: string;
5168
- name: string;
5169
- };
5170
- inviter: {
5171
- name: string;
5172
- };
5173
- email: string;
5174
- role: string;
5175
- appRoles: string[];
5176
- expiresAt: string;
5177
- hasAccount: boolean;
5166
+ total: number;
5178
5167
  }>;
5179
5168
  acceptInvitation: import("better-auth").StrictEndpoint<"/invitation/accept", {
5180
5169
  method: "POST";
@@ -5214,6 +5203,48 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
5214
5203
  organizationId: string;
5215
5204
  };
5216
5205
  }>;
5206
+ };
5207
+ hooks: {
5208
+ after: {
5209
+ matcher: (context: {
5210
+ path?: string;
5211
+ }) => boolean;
5212
+ handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
5213
+ }[];
5214
+ };
5215
+ })[], {
5216
+ id: "protobase-users";
5217
+ endpoints: {
5218
+ getInvitation: import("better-auth").StrictEndpoint<"/invitation", {
5219
+ method: "GET";
5220
+ query: import("zod").ZodObject<{
5221
+ token: import("zod").ZodString;
5222
+ }, import("zod/v4/core").$strip>;
5223
+ }, {
5224
+ appRoles: string[];
5225
+ inviter: {
5226
+ name: string;
5227
+ };
5228
+ email: string;
5229
+ expiresAt: string;
5230
+ hasAccount: boolean;
5231
+ app: {
5232
+ name: string;
5233
+ };
5234
+ } | {
5235
+ role: string;
5236
+ appRoles: string[];
5237
+ inviter: {
5238
+ name: string;
5239
+ };
5240
+ email: string;
5241
+ expiresAt: string;
5242
+ hasAccount: boolean;
5243
+ organization: {
5244
+ id: string;
5245
+ name: string;
5246
+ };
5247
+ }>;
5217
5248
  signUpFromInvitation: import("better-auth").StrictEndpoint<"/invitation/sign-up", {
5218
5249
  method: "POST";
5219
5250
  body: import("zod").ZodObject<{
@@ -5222,6 +5253,11 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
5222
5253
  password: import("zod").ZodOptional<import("zod").ZodString>;
5223
5254
  }, import("zod/v4/core").$strip>;
5224
5255
  }, {
5256
+ user: {
5257
+ id: string;
5258
+ email: string;
5259
+ };
5260
+ } | {
5225
5261
  member: {
5226
5262
  appRoles: string[];
5227
5263
  id: string;
@@ -5231,6 +5267,408 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
5231
5267
  organizationId: string;
5232
5268
  };
5233
5269
  }>;
5270
+ inviteUser: import("better-auth").StrictEndpoint<"/users/invite", {
5271
+ method: "POST";
5272
+ use: import("better-auth").Middleware<{
5273
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
5274
+ session: {
5275
+ session: Record<string, any> & {
5276
+ id: string;
5277
+ createdAt: Date;
5278
+ updatedAt: Date;
5279
+ userId: string;
5280
+ expiresAt: Date;
5281
+ token: string;
5282
+ ipAddress?: string | null | undefined;
5283
+ userAgent?: string | null | undefined;
5284
+ };
5285
+ user: Record<string, any> & {
5286
+ id: string;
5287
+ createdAt: Date;
5288
+ updatedAt: Date;
5289
+ email: string;
5290
+ emailVerified: boolean;
5291
+ name: string;
5292
+ image?: string | null | undefined;
5293
+ };
5294
+ };
5295
+ }>>[];
5296
+ }, (inputContext: import("better-auth").MiddlewareInputContext<{
5297
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
5298
+ session: {
5299
+ session: Record<string, any> & {
5300
+ id: string;
5301
+ createdAt: Date;
5302
+ updatedAt: Date;
5303
+ userId: string;
5304
+ expiresAt: Date;
5305
+ token: string;
5306
+ ipAddress?: string | null | undefined;
5307
+ userAgent?: string | null | undefined;
5308
+ };
5309
+ user: Record<string, any> & {
5310
+ id: string;
5311
+ createdAt: Date;
5312
+ updatedAt: Date;
5313
+ email: string;
5314
+ emailVerified: boolean;
5315
+ name: string;
5316
+ image?: string | null | undefined;
5317
+ };
5318
+ };
5319
+ }>>[];
5320
+ }>) => Promise<{
5321
+ session: {
5322
+ session: Record<string, any> & {
5323
+ id: string;
5324
+ createdAt: Date;
5325
+ updatedAt: Date;
5326
+ userId: string;
5327
+ expiresAt: Date;
5328
+ token: string;
5329
+ ipAddress?: string | null | undefined;
5330
+ userAgent?: string | null | undefined;
5331
+ };
5332
+ user: Record<string, any> & {
5333
+ id: string;
5334
+ createdAt: Date;
5335
+ updatedAt: Date;
5336
+ email: string;
5337
+ emailVerified: boolean;
5338
+ name: string;
5339
+ image?: string | null | undefined;
5340
+ };
5341
+ } & {
5342
+ session: {
5343
+ id: string;
5344
+ createdAt: Date;
5345
+ updatedAt: Date;
5346
+ userId: string;
5347
+ expiresAt: Date;
5348
+ token: string;
5349
+ ipAddress?: string | null | undefined;
5350
+ userAgent?: string | null | undefined;
5351
+ } & Record<string, any>;
5352
+ user: {
5353
+ id: string;
5354
+ createdAt: Date;
5355
+ updatedAt: Date;
5356
+ email: string;
5357
+ emailVerified: boolean;
5358
+ name: string;
5359
+ image?: string | null | undefined;
5360
+ } & Record<string, any>;
5361
+ };
5362
+ }>>[];
5363
+ body: import("zod").ZodObject<{
5364
+ email: import("zod").ZodEmail;
5365
+ roles: import("zod").ZodArray<import("zod").ZodString>;
5366
+ }, import("zod/v4/core").$strip>;
5367
+ }, {
5368
+ id: string;
5369
+ email: string;
5370
+ roles: string[];
5371
+ expiresAt: string;
5372
+ }>;
5373
+ listUserInvitations: import("better-auth").StrictEndpoint<"/users/invitations", {
5374
+ method: "GET";
5375
+ use: import("better-auth").Middleware<{
5376
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
5377
+ session: {
5378
+ session: Record<string, any> & {
5379
+ id: string;
5380
+ createdAt: Date;
5381
+ updatedAt: Date;
5382
+ userId: string;
5383
+ expiresAt: Date;
5384
+ token: string;
5385
+ ipAddress?: string | null | undefined;
5386
+ userAgent?: string | null | undefined;
5387
+ };
5388
+ user: Record<string, any> & {
5389
+ id: string;
5390
+ createdAt: Date;
5391
+ updatedAt: Date;
5392
+ email: string;
5393
+ emailVerified: boolean;
5394
+ name: string;
5395
+ image?: string | null | undefined;
5396
+ };
5397
+ };
5398
+ }>>[];
5399
+ }, (inputContext: import("better-auth").MiddlewareInputContext<{
5400
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
5401
+ session: {
5402
+ session: Record<string, any> & {
5403
+ id: string;
5404
+ createdAt: Date;
5405
+ updatedAt: Date;
5406
+ userId: string;
5407
+ expiresAt: Date;
5408
+ token: string;
5409
+ ipAddress?: string | null | undefined;
5410
+ userAgent?: string | null | undefined;
5411
+ };
5412
+ user: Record<string, any> & {
5413
+ id: string;
5414
+ createdAt: Date;
5415
+ updatedAt: Date;
5416
+ email: string;
5417
+ emailVerified: boolean;
5418
+ name: string;
5419
+ image?: string | null | undefined;
5420
+ };
5421
+ };
5422
+ }>>[];
5423
+ }>) => Promise<{
5424
+ session: {
5425
+ session: Record<string, any> & {
5426
+ id: string;
5427
+ createdAt: Date;
5428
+ updatedAt: Date;
5429
+ userId: string;
5430
+ expiresAt: Date;
5431
+ token: string;
5432
+ ipAddress?: string | null | undefined;
5433
+ userAgent?: string | null | undefined;
5434
+ };
5435
+ user: Record<string, any> & {
5436
+ id: string;
5437
+ createdAt: Date;
5438
+ updatedAt: Date;
5439
+ email: string;
5440
+ emailVerified: boolean;
5441
+ name: string;
5442
+ image?: string | null | undefined;
5443
+ };
5444
+ } & {
5445
+ session: {
5446
+ id: string;
5447
+ createdAt: Date;
5448
+ updatedAt: Date;
5449
+ userId: string;
5450
+ expiresAt: Date;
5451
+ token: string;
5452
+ ipAddress?: string | null | undefined;
5453
+ userAgent?: string | null | undefined;
5454
+ } & Record<string, any>;
5455
+ user: {
5456
+ id: string;
5457
+ createdAt: Date;
5458
+ updatedAt: Date;
5459
+ email: string;
5460
+ emailVerified: boolean;
5461
+ name: string;
5462
+ image?: string | null | undefined;
5463
+ } & Record<string, any>;
5464
+ };
5465
+ }>>[];
5466
+ }, {
5467
+ invitations: {
5468
+ id: string;
5469
+ email: string;
5470
+ roles: string[];
5471
+ expiresAt: string;
5472
+ }[];
5473
+ }>;
5474
+ cancelUserInvitation: import("better-auth").StrictEndpoint<"/users/invitations/cancel", {
5475
+ method: "POST";
5476
+ use: import("better-auth").Middleware<{
5477
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
5478
+ session: {
5479
+ session: Record<string, any> & {
5480
+ id: string;
5481
+ createdAt: Date;
5482
+ updatedAt: Date;
5483
+ userId: string;
5484
+ expiresAt: Date;
5485
+ token: string;
5486
+ ipAddress?: string | null | undefined;
5487
+ userAgent?: string | null | undefined;
5488
+ };
5489
+ user: Record<string, any> & {
5490
+ id: string;
5491
+ createdAt: Date;
5492
+ updatedAt: Date;
5493
+ email: string;
5494
+ emailVerified: boolean;
5495
+ name: string;
5496
+ image?: string | null | undefined;
5497
+ };
5498
+ };
5499
+ }>>[];
5500
+ }, (inputContext: import("better-auth").MiddlewareInputContext<{
5501
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
5502
+ session: {
5503
+ session: Record<string, any> & {
5504
+ id: string;
5505
+ createdAt: Date;
5506
+ updatedAt: Date;
5507
+ userId: string;
5508
+ expiresAt: Date;
5509
+ token: string;
5510
+ ipAddress?: string | null | undefined;
5511
+ userAgent?: string | null | undefined;
5512
+ };
5513
+ user: Record<string, any> & {
5514
+ id: string;
5515
+ createdAt: Date;
5516
+ updatedAt: Date;
5517
+ email: string;
5518
+ emailVerified: boolean;
5519
+ name: string;
5520
+ image?: string | null | undefined;
5521
+ };
5522
+ };
5523
+ }>>[];
5524
+ }>) => Promise<{
5525
+ session: {
5526
+ session: Record<string, any> & {
5527
+ id: string;
5528
+ createdAt: Date;
5529
+ updatedAt: Date;
5530
+ userId: string;
5531
+ expiresAt: Date;
5532
+ token: string;
5533
+ ipAddress?: string | null | undefined;
5534
+ userAgent?: string | null | undefined;
5535
+ };
5536
+ user: Record<string, any> & {
5537
+ id: string;
5538
+ createdAt: Date;
5539
+ updatedAt: Date;
5540
+ email: string;
5541
+ emailVerified: boolean;
5542
+ name: string;
5543
+ image?: string | null | undefined;
5544
+ };
5545
+ } & {
5546
+ session: {
5547
+ id: string;
5548
+ createdAt: Date;
5549
+ updatedAt: Date;
5550
+ userId: string;
5551
+ expiresAt: Date;
5552
+ token: string;
5553
+ ipAddress?: string | null | undefined;
5554
+ userAgent?: string | null | undefined;
5555
+ } & Record<string, any>;
5556
+ user: {
5557
+ id: string;
5558
+ createdAt: Date;
5559
+ updatedAt: Date;
5560
+ email: string;
5561
+ emailVerified: boolean;
5562
+ name: string;
5563
+ image?: string | null | undefined;
5564
+ } & Record<string, any>;
5565
+ };
5566
+ }>>[];
5567
+ body: import("zod").ZodObject<{
5568
+ id: import("zod").ZodString;
5569
+ }, import("zod/v4/core").$strip>;
5570
+ }, {
5571
+ id: string;
5572
+ }>;
5573
+ userRoles: import("better-auth").StrictEndpoint<"/users/roles", {
5574
+ method: "GET";
5575
+ use: import("better-auth").Middleware<{
5576
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
5577
+ session: {
5578
+ session: Record<string, any> & {
5579
+ id: string;
5580
+ createdAt: Date;
5581
+ updatedAt: Date;
5582
+ userId: string;
5583
+ expiresAt: Date;
5584
+ token: string;
5585
+ ipAddress?: string | null | undefined;
5586
+ userAgent?: string | null | undefined;
5587
+ };
5588
+ user: Record<string, any> & {
5589
+ id: string;
5590
+ createdAt: Date;
5591
+ updatedAt: Date;
5592
+ email: string;
5593
+ emailVerified: boolean;
5594
+ name: string;
5595
+ image?: string | null | undefined;
5596
+ };
5597
+ };
5598
+ }>>[];
5599
+ }, (inputContext: import("better-auth").MiddlewareInputContext<{
5600
+ use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
5601
+ session: {
5602
+ session: Record<string, any> & {
5603
+ id: string;
5604
+ createdAt: Date;
5605
+ updatedAt: Date;
5606
+ userId: string;
5607
+ expiresAt: Date;
5608
+ token: string;
5609
+ ipAddress?: string | null | undefined;
5610
+ userAgent?: string | null | undefined;
5611
+ };
5612
+ user: Record<string, any> & {
5613
+ id: string;
5614
+ createdAt: Date;
5615
+ updatedAt: Date;
5616
+ email: string;
5617
+ emailVerified: boolean;
5618
+ name: string;
5619
+ image?: string | null | undefined;
5620
+ };
5621
+ };
5622
+ }>>[];
5623
+ }>) => Promise<{
5624
+ session: {
5625
+ session: Record<string, any> & {
5626
+ id: string;
5627
+ createdAt: Date;
5628
+ updatedAt: Date;
5629
+ userId: string;
5630
+ expiresAt: Date;
5631
+ token: string;
5632
+ ipAddress?: string | null | undefined;
5633
+ userAgent?: string | null | undefined;
5634
+ };
5635
+ user: Record<string, any> & {
5636
+ id: string;
5637
+ createdAt: Date;
5638
+ updatedAt: Date;
5639
+ email: string;
5640
+ emailVerified: boolean;
5641
+ name: string;
5642
+ image?: string | null | undefined;
5643
+ };
5644
+ } & {
5645
+ session: {
5646
+ id: string;
5647
+ createdAt: Date;
5648
+ updatedAt: Date;
5649
+ userId: string;
5650
+ expiresAt: Date;
5651
+ token: string;
5652
+ ipAddress?: string | null | undefined;
5653
+ userAgent?: string | null | undefined;
5654
+ } & Record<string, any>;
5655
+ user: {
5656
+ id: string;
5657
+ createdAt: Date;
5658
+ updatedAt: Date;
5659
+ email: string;
5660
+ emailVerified: boolean;
5661
+ name: string;
5662
+ image?: string | null | undefined;
5663
+ } & Record<string, any>;
5664
+ };
5665
+ }>>[];
5666
+ }, {
5667
+ name: string;
5668
+ label: string;
5669
+ membership: boolean;
5670
+ grants: string[];
5671
+ }[]>;
5234
5672
  };
5235
5673
  hooks: {
5236
5674
  after: {
@@ -5240,7 +5678,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
5240
5678
  handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
5241
5679
  }[];
5242
5680
  };
5243
- })[]];
5681
+ }];
5244
5682
  disabledPaths: string[];
5245
5683
  databaseHooks: {
5246
5684
  session?: {
@@ -3,6 +3,8 @@ import { defaultAppName, readAppName } from "../app-name.js";
3
3
  import { authBasePath } from "./auth-base-path.js";
4
4
  import { platformMailer } from "../mail/platform-mailer.js";
5
5
  import { readOperatorSettings, resolveOperator } from "./operator-provider.js";
6
+ import { defaultInvitationUrl } from "./invitations/invitation-link-hook.js";
7
+ import { lastAdminGuardPlugin } from "./last-admin-guard.js";
6
8
  import { roleDefinitions } from "./organizations/role-definitions.js";
7
9
  import { lastOrganizationField, organizationClaims, sessionOrganizationHooks } from "./organizations/session-organization.js";
8
10
  import { organizationPlugin } from "./organizations/organization-plugin.js";
@@ -21,6 +23,7 @@ import { emailCodeOptions, twoFactorCodeOptions, unusedEmailCodePaths } from "./
21
23
  import { signUpPaths, signUpPlugin } from "./sign-up/sign-up-plugin.js";
22
24
  import { staffSignInPlugin } from "./staff-plugin.js";
23
25
  import { twoFactorAfterPasswordOrCode } from "./two-factor-challenge.js";
26
+ import { usersPlugin } from "./users/users-plugin.js";
24
27
  import { APIError } from "better-auth/api";
25
28
  import { betterAuth } from "better-auth";
26
29
  import { admin, emailOTP, genericOAuth, jwt } from "better-auth/plugins";
@@ -143,6 +146,7 @@ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, defini
143
146
  ...mail && { mail }
144
147
  }),
145
148
  rolesPlugin({ definitions }),
149
+ lastAdminGuardPlugin(),
146
150
  ...organizations ? [organizationPlugin({
147
151
  resolved: organizations,
148
152
  secret: options.secret,
@@ -151,7 +155,14 @@ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, defini
151
155
  }), protobaseOrganizationPlugin({
152
156
  resolved: organizations,
153
157
  mail: Boolean(mailer)
154
- })] : []
158
+ })] : [],
159
+ usersPlugin({
160
+ definitions,
161
+ ...mail && { mail },
162
+ invitationUrl: organizations?.invitationUrl ?? defaultInvitationUrl(options.baseURL),
163
+ invitationSeconds: organizations?.invitationExpiresIn ?? 604800,
164
+ ...organizations && { organizations }
165
+ })
155
166
  ],
156
167
  disabledPaths: [
157
168
  ...unusedEmailCodePaths,
@@ -0,0 +1,50 @@
1
+ import { effectiveSignInPolicy } from "../sign-in-policy.js";
2
+ import { readSignInPolicy } from "../policy-store.js";
3
+ import { checkNewAccountPassword } from "../new-account-password.js";
4
+ import { setSessionCookie } from "better-auth/cookies";
5
+ //#region src/better-auth/invitations/account-from-invitation.ts
6
+ /**
7
+ * Creates the account of an invited address: verified, since the invitation link proves the person reads it, with
8
+ * `role` and, when given, a password checked against the sign-in policy. A password is needed unless the policy offers
9
+ * emailed codes.
10
+ */
11
+ const createInvitedAccount = async (ctx, input) => {
12
+ const { internalAdapter } = ctx.context;
13
+ checkNewAccountPassword(effectiveSignInPolicy((await readSignInPolicy(ctx.context.adapter)).policy, { mail: input.mail }), input.password);
14
+ const user = await internalAdapter.createUser({
15
+ email: input.email.toLowerCase(),
16
+ name: input.name,
17
+ emailVerified: true,
18
+ role: input.role
19
+ }, { method: "invitation" });
20
+ if (input.password !== void 0) await internalAdapter.linkAccount({
21
+ userId: user.id,
22
+ providerId: "credential",
23
+ accountId: user.id,
24
+ password: await ctx.context.password.hash(input.password)
25
+ });
26
+ return user;
27
+ };
28
+ /** Signs the new account in, in `activeOrganizationId` when given; the policy's required methods are then set up as after any sign-in. */
29
+ const signInInvitedAccount = async (ctx, user, activeOrganizationId) => {
30
+ const { internalAdapter } = ctx.context;
31
+ const session = await internalAdapter.createSession(user.id, false);
32
+ if (activeOrganizationId === void 0) {
33
+ await setSessionCookie(ctx, {
34
+ session,
35
+ user
36
+ });
37
+ return session;
38
+ }
39
+ await internalAdapter.updateSession(session.token, { activeOrganizationId });
40
+ await setSessionCookie(ctx, {
41
+ session: {
42
+ ...session,
43
+ activeOrganizationId
44
+ },
45
+ user
46
+ });
47
+ return session;
48
+ };
49
+ //#endregion
50
+ export { createInvitedAccount, signInInvitedAccount };