@protobase/server 0.15.4 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/app-name.js +9 -0
  2. package/dist/better-auth/auth-mail/account-exists-email.d.ts +1 -0
  3. package/dist/better-auth/auth-mail/account-exists-email.js +31 -0
  4. package/dist/better-auth/auth-mail/auth-email-layout.js +90 -0
  5. package/dist/better-auth/auth-mail/auth-emails.d.ts +7 -0
  6. package/dist/better-auth/auth-mail/auth-emails.js +8 -0
  7. package/dist/better-auth/auth-mail/invitation-email.d.ts +1 -0
  8. package/dist/better-auth/auth-mail/invitation-email.js +38 -0
  9. package/dist/better-auth/auth-mail/mailing-app.js +11 -0
  10. package/dist/better-auth/auth-mail/reset-password-email.d.ts +1 -0
  11. package/dist/better-auth/auth-mail/reset-password-email.js +35 -0
  12. package/dist/better-auth/auth-mail/send-auth-email.d.ts +1 -0
  13. package/dist/better-auth/auth-mail/send-auth-email.js +15 -0
  14. package/dist/better-auth/auth-mail/sign-in-code-email.d.ts +1 -0
  15. package/dist/better-auth/auth-mail/sign-in-code-email.js +32 -0
  16. package/dist/better-auth/auth-mail/sign-up-code-email.d.ts +1 -0
  17. package/dist/better-auth/auth-mail/sign-up-code-email.js +32 -0
  18. package/dist/better-auth/auth-mail/staff-sign-in-email.d.ts +1 -0
  19. package/dist/better-auth/auth-mail/staff-sign-in-email.js +39 -0
  20. package/dist/better-auth/auth-mail/two-factor-code-email.d.ts +1 -0
  21. package/dist/better-auth/auth-mail/two-factor-code-email.js +32 -0
  22. package/dist/better-auth/create-auth.d.ts +43 -181
  23. package/dist/better-auth/create-auth.js +24 -11
  24. package/dist/better-auth/organizations/organization-plugin.js +8 -8
  25. package/dist/better-auth/password-reset.js +8 -21
  26. package/dist/better-auth/sign-in-mail.js +14 -55
  27. package/dist/better-auth/sign-up/sign-up-code.js +2 -1
  28. package/dist/better-auth/sign-up/sign-up-plugin.d.ts +2 -0
  29. package/dist/better-auth/sign-up/sign-up-plugin.js +37 -22
  30. package/dist/better-auth/sign-up/sign-up-ticket.js +34 -0
  31. package/dist/better-auth/staff-plugin.js +2 -2
  32. package/dist/better-auth/staff-sign-in-endpoints.js +5 -6
  33. package/dist/check-views.js +5 -0
  34. package/dist/index.d.ts +1 -1
  35. package/dist/mail/platform-mailer.js +10 -3
  36. package/dist/mail/smtp-mailer.js +6 -2
  37. package/dist/view-access.js +6 -1
  38. package/dist/view-map.js +12 -2
  39. package/package.json +5 -4
  40. package/dist/better-auth/organizations/invitation-mail.js +0 -17
  41. package/dist/better-auth/sign-up/sign-up-mail.js +0 -29
@@ -28,7 +28,11 @@ export type CreateAuthOptions = {
28
28
  * passes in `PROTOBASE_PASSKEY_DOMAIN`, when set, and to the host of `baseURL` otherwise.
29
29
  */
30
30
  passkeyDomain?: string;
31
- /** The name authenticator apps and passkey prompts show for this app. Default `Protobase`. */
31
+ /**
32
+ * The app's name: authenticator apps and passkey prompts show it, the auth emails name the app with it, and the
33
+ * default mailer sends them from it, as the sender's display name. Defaults to the name the platform passes in
34
+ * `PROTOBASE_APP_NAME`, when set, and to `Protobase` otherwise (without a sender's display name).
35
+ */
32
36
  appName?: string;
33
37
  /** Signs cookies and encrypts the JWT private keys. Generate with `openssl rand -base64 32`. */
34
38
  secret: string;
@@ -57,9 +61,10 @@ export type CreateAuthOptions = {
57
61
  /** Sign-in attempts allowed per minute and client, default 5; also the sign-up requests allowed. */
58
62
  signInPerMinute?: number;
59
63
  /**
60
- * Sends the password-reset email and the emailed sign-in and two-factor codes; without a mailer none of them is
61
- * offered. Defaults to SMTP with the settings the platform passes in `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM`
62
- * (see `readMailSettings`), when set; `false` turns mail off whatever the environment says.
64
+ * Sends the auth emails: the password-reset email, the emailed sign-in and two-factor codes, and those of sign-up,
65
+ * staff sign-in and invitations; without a mailer none of them is offered. Defaults to SMTP with the settings the
66
+ * platform passes in `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (see `readMailSettings`), when set; `false`
67
+ * turns mail off whatever the environment says.
63
68
  */
64
69
  mailer?: Mailer | false;
65
70
  /**
@@ -743,7 +748,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
743
748
  expiresAt: Date;
744
749
  token: string;
745
750
  ipAddress?: string | null | undefined;
746
- userAgent? /** Open sign-up is on and offered: the app asks for it, and can mail the codes. */ : string | null | undefined;
751
+ userAgent?: string | null | undefined;
747
752
  };
748
753
  };
749
754
  }>>[];
@@ -2717,10 +2722,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
2717
2722
  email: string;
2718
2723
  emailVerified: boolean;
2719
2724
  name: string;
2720
- image? /**
2721
- * Turns on organizations: people work in one at a time, records of `.tenant` resources are scoped to it, and roles
2722
- * are held globally (on the user) or per membership. Off by default: the app works as one organization.
2723
- */ : string | null | undefined;
2725
+ image?: string | null | undefined;
2724
2726
  } & Record<string, any>;
2725
2727
  }>;
2726
2728
  signInEmailOTP: import("better-auth").StrictEndpoint<"/sign-in/email-otp", {
@@ -3039,11 +3041,19 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3039
3041
  }, {
3040
3042
  sent: boolean;
3041
3043
  }>;
3042
- createSignUpAccount: import("better-auth").StrictEndpoint<string, {
3044
+ verifySignUpCode: import("better-auth").StrictEndpoint<string, {
3043
3045
  method: "POST";
3044
3046
  body: import("zod").ZodObject<{
3045
3047
  email: import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodEmail>;
3046
3048
  code: import("zod").ZodString;
3049
+ }, import("zod/v4/core").$strip>;
3050
+ }, {
3051
+ ticket: string;
3052
+ }>;
3053
+ createSignUpAccount: import("better-auth").StrictEndpoint<string, {
3054
+ method: "POST";
3055
+ body: import("zod").ZodObject<{
3056
+ ticket: import("zod").ZodString;
3047
3057
  name: import("zod").ZodString;
3048
3058
  password: import("zod").ZodOptional<import("zod").ZodString>;
3049
3059
  }, import("zod/v4/core").$strip>;
@@ -3141,15 +3151,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3141
3151
  email: string;
3142
3152
  emailVerified: boolean;
3143
3153
  name: string;
3144
- image?
3145
- /**
3146
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3147
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3148
- */
3149
- /**
3150
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3151
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3152
- */ : string | null | undefined;
3154
+ image?: string | null | undefined;
3153
3155
  };
3154
3156
  };
3155
3157
  }>>[];
@@ -3173,15 +3175,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3173
3175
  email: string;
3174
3176
  emailVerified: boolean;
3175
3177
  name: string;
3176
- image?
3177
- /**
3178
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3179
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3180
- */
3181
- /**
3182
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3183
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3184
- */ : string | null | undefined;
3178
+ image?: string | null | undefined;
3185
3179
  };
3186
3180
  };
3187
3181
  }>>[];
@@ -3204,15 +3198,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3204
3198
  email: string;
3205
3199
  emailVerified: boolean;
3206
3200
  name: string;
3207
- image?
3208
- /**
3209
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3210
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3211
- */
3212
- /**
3213
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3214
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3215
- */ : string | null | undefined;
3201
+ image?: string | null | undefined;
3216
3202
  };
3217
3203
  } & {
3218
3204
  session: {
@@ -3267,15 +3253,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3267
3253
  email: string;
3268
3254
  emailVerified: boolean;
3269
3255
  name: string;
3270
- image?
3271
- /**
3272
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3273
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3274
- */
3275
- /**
3276
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3277
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3278
- */ : string | null | undefined;
3256
+ image?: string | null | undefined;
3279
3257
  };
3280
3258
  };
3281
3259
  }>>[];
@@ -3299,15 +3277,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3299
3277
  email: string;
3300
3278
  emailVerified: boolean;
3301
3279
  name: string;
3302
- image?
3303
- /**
3304
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3305
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3306
- */
3307
- /**
3308
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3309
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3310
- */ : string | null | undefined;
3280
+ image?: string | null | undefined;
3311
3281
  };
3312
3282
  };
3313
3283
  }>>[];
@@ -3330,15 +3300,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3330
3300
  email: string;
3331
3301
  emailVerified: boolean;
3332
3302
  name: string;
3333
- image?
3334
- /**
3335
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3336
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3337
- */
3338
- /**
3339
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3340
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3341
- */ : string | null | undefined;
3303
+ image?: string | null | undefined;
3342
3304
  };
3343
3305
  } & {
3344
3306
  session: {
@@ -3393,15 +3355,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3393
3355
  email: string;
3394
3356
  emailVerified: boolean;
3395
3357
  name: string;
3396
- image?
3397
- /**
3398
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3399
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3400
- */
3401
- /**
3402
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3403
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3404
- */ : string | null | undefined;
3358
+ image?: string | null | undefined;
3405
3359
  };
3406
3360
  };
3407
3361
  }>>[];
@@ -3506,15 +3460,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3506
3460
  email: string;
3507
3461
  emailVerified: boolean;
3508
3462
  name: string;
3509
- image?
3510
- /**
3511
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3512
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3513
- */
3514
- /**
3515
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3516
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3517
- */ : string | null | undefined;
3463
+ image?: string | null | undefined;
3518
3464
  };
3519
3465
  };
3520
3466
  }>>[];
@@ -3542,15 +3488,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3542
3488
  email: string;
3543
3489
  emailVerified: boolean;
3544
3490
  name: string;
3545
- image?
3546
- /**
3547
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3548
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3549
- */
3550
- /**
3551
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3552
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3553
- */ : string | null | undefined;
3491
+ image?: string | null | undefined;
3554
3492
  };
3555
3493
  };
3556
3494
  }>>[];
@@ -3579,15 +3517,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3579
3517
  email: string;
3580
3518
  emailVerified: boolean;
3581
3519
  name: string;
3582
- image?
3583
- /**
3584
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3585
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3586
- */
3587
- /**
3588
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3589
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3590
- */ : string | null | undefined;
3520
+ image?: string | null | undefined;
3591
3521
  };
3592
3522
  };
3593
3523
  }>>[];
@@ -3611,15 +3541,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3611
3541
  email: string;
3612
3542
  emailVerified: boolean;
3613
3543
  name: string;
3614
- image?
3615
- /**
3616
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3617
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3618
- */
3619
- /**
3620
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3621
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3622
- */ : string | null | undefined;
3544
+ image?: string | null | undefined;
3623
3545
  };
3624
3546
  };
3625
3547
  }>>[];
@@ -3642,15 +3564,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3642
3564
  email: string;
3643
3565
  emailVerified: boolean;
3644
3566
  name: string;
3645
- image?
3646
- /**
3647
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3648
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3649
- */
3650
- /**
3651
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3652
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3653
- */ : string | null | undefined;
3567
+ image?: string | null | undefined;
3654
3568
  };
3655
3569
  } & {
3656
3570
  session: {
@@ -3747,15 +3661,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3747
3661
  email: string;
3748
3662
  emailVerified: boolean;
3749
3663
  name: string;
3750
- image?
3751
- /**
3752
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3753
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3754
- */
3755
- /**
3756
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3757
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3758
- */ : string | null | undefined;
3664
+ image?: string | null | undefined;
3759
3665
  };
3760
3666
  };
3761
3667
  }>>[];
@@ -3787,15 +3693,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3787
3693
  email: string;
3788
3694
  emailVerified: boolean;
3789
3695
  name: string;
3790
- image?
3791
- /**
3792
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3793
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3794
- */
3795
- /**
3796
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
3797
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
3798
- */ : string | null | undefined;
3696
+ image?: string | null | undefined;
3799
3697
  };
3800
3698
  };
3801
3699
  }>>[];
@@ -4123,15 +4021,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
4123
4021
  email: string;
4124
4022
  emailVerified: boolean;
4125
4023
  name: string;
4126
- image?
4127
- /**
4128
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4129
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4130
- */
4131
- /**
4132
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4133
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4134
- */ : string | null | undefined;
4024
+ image?: string | null | undefined;
4135
4025
  };
4136
4026
  };
4137
4027
  }>>[];
@@ -4170,15 +4060,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
4170
4060
  email: string;
4171
4061
  emailVerified: boolean;
4172
4062
  name: string;
4173
- image?
4174
- /**
4175
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4176
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4177
- */
4178
- /**
4179
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4180
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4181
- */ : string | null | undefined;
4063
+ image?: string | null | undefined;
4182
4064
  };
4183
4065
  };
4184
4066
  }>>[];
@@ -4213,15 +4095,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
4213
4095
  email: string;
4214
4096
  emailVerified: boolean;
4215
4097
  name: string;
4216
- image?
4217
- /**
4218
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4219
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4220
- */
4221
- /**
4222
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4223
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4224
- */ : string | null | undefined;
4098
+ image?: string | null | undefined;
4225
4099
  };
4226
4100
  };
4227
4101
  }>>[];
@@ -4261,15 +4135,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
4261
4135
  email: string;
4262
4136
  emailVerified: boolean;
4263
4137
  name: string;
4264
- image?
4265
- /**
4266
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4267
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4268
- */
4269
- /**
4270
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4271
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4272
- */ : string | null | undefined;
4138
+ image?: string | null | undefined;
4273
4139
  };
4274
4140
  };
4275
4141
  }>>[];
@@ -4326,15 +4192,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
4326
4192
  email: string;
4327
4193
  emailVerified: boolean;
4328
4194
  name: string;
4329
- image?
4330
- /**
4331
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4332
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4333
- */
4334
- /**
4335
- * The role of a user created without one. Optional: when unset, and more than one role besides `admin` exists,
4336
- * creating a user without a role is an error that asks for one. With exactly one other role, that role is the default.
4337
- */ : string | null | undefined;
4195
+ image?: string | null | undefined;
4338
4196
  };
4339
4197
  };
4340
4198
  }>>[];
@@ -4430,6 +4288,10 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
4430
4288
  window: number;
4431
4289
  max: number;
4432
4290
  };
4291
+ [signUpPaths.verifyCode]: {
4292
+ window: number;
4293
+ max: number;
4294
+ };
4433
4295
  [signUpPaths.create]: {
4434
4296
  window: number;
4435
4297
  max: number;
@@ -1,4 +1,5 @@
1
1
  import { multiHostBaseURL, readOrigins, resolveOrigins } from "./origins.js";
2
+ import { readAppName } from "../app-name.js";
2
3
  import { platformMailer } from "../mail/platform-mailer.js";
3
4
  import { readOperatorSettings, resolveOperator } from "./operator-provider.js";
4
5
  import { roleDefinitions } from "./organizations/role-definitions.js";
@@ -27,6 +28,8 @@ const platformOperator = () => readOperatorSettings(globalThis.process?.env ?? {
27
28
  const platformSignInSettings = () => readPlatformSignIn(globalThis.process?.env ?? {});
28
29
  const platformOrigins = () => readOrigins(globalThis.process?.env ?? {});
29
30
  const platformPasskeyDomain = () => readPasskeyDomain(globalThis.process?.env ?? {});
31
+ const platformAppName = () => readAppName(globalThis.process?.env ?? {});
32
+ const defaultAppName = "Protobase";
30
33
  const tokenLifetime = "15m";
31
34
  const authBasePath = "/api/auth";
32
35
  /**
@@ -44,12 +47,17 @@ const organizationPaths = ["/organization/set-active", "/organization/accept-inv
44
47
  * The options `createAuth` gives Better Auth, with the roles, default role, mailer, operator provider and platform
45
48
  * sign-in provider already resolved.
46
49
  */
47
- const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, definitions, defaultRole, mailer, signUpRole, operator, platformSignIn, organizations, context = noContext }) => {
50
+ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, definitions, defaultRole, appName = defaultAppName, mailer, signUpRole, operator, platformSignIn, organizations, context = noContext }) => {
48
51
  const secure = options.baseURL.startsWith("https://");
49
52
  const signIn = platformSignInFor(platformSignIn, Object.keys(options.socialProviders ?? {}));
50
53
  const hosts = passkeyHosts([options.baseURL, ...origins]);
54
+ const mail = mailer && {
55
+ mailer,
56
+ appName,
57
+ baseURL: options.baseURL
58
+ };
51
59
  return {
52
- appName: options.appName ?? "Protobase",
60
+ appName,
53
61
  database: options.database,
54
62
  baseURL: multiHostBaseURL(options.baseURL, origins),
55
63
  basePath: authBasePath,
@@ -64,7 +72,7 @@ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, defini
64
72
  enabled: true,
65
73
  disableSignUp: true,
66
74
  minPasswordLength: 12,
67
- ...mailer && passwordResetOptions(mailer)
75
+ ...mail && passwordResetOptions(mail)
68
76
  },
69
77
  ...options.socialProviders && { socialProviders: options.socialProviders },
70
78
  user: organizations ? {
@@ -107,18 +115,17 @@ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, defini
107
115
  twoFactorAfterPasswordOrCode({
108
116
  schema: pluginNames.twoFactor,
109
117
  allowPasswordless: true,
110
- ...mailer && { otpOptions: twoFactorCodeOptions(mailer) }
118
+ ...mail && { otpOptions: twoFactorCodeOptions(mail) }
111
119
  }),
112
120
  passkeyPlugin({
113
121
  domain: passkeyDomain ?? hosts[0],
114
122
  hosts,
115
123
  formerDomain: hosts[0]
116
124
  }),
117
- ...mailer ? [emailOTP(emailCodeOptions(mailer))] : [],
118
- ...mailer && signUpRole ? [signUpPlugin({
125
+ ...mail ? [emailOTP(emailCodeOptions(mail))] : [],
126
+ ...mail && signUpRole ? [signUpPlugin({
119
127
  role: signUpRole,
120
- mailer,
121
- appName: options.appName ?? "Protobase"
128
+ mail
122
129
  })] : [],
123
130
  ...signIn ? [genericOAuth({ config: [platformSignInProvider(signIn)] })] : [],
124
131
  signInPolicyPlugin({
@@ -132,13 +139,13 @@ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, defini
132
139
  }),
133
140
  staffSignInPlugin({
134
141
  ...operator && { operator },
135
- ...mailer && { mailer }
142
+ ...mail && { mail }
136
143
  }),
137
144
  rolesPlugin({ definitions }),
138
145
  ...organizations ? [organizationPlugin({
139
146
  resolved: organizations,
140
147
  secret: options.secret,
141
- ...mailer && { mailer },
148
+ ...mail && { mail },
142
149
  context
143
150
  }), protobaseOrganizationPlugin({
144
151
  resolved: organizations,
@@ -186,6 +193,10 @@ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, defini
186
193
  window: 60,
187
194
  max: options.signInPerMinute ?? 5
188
195
  },
196
+ [signUpPaths.verifyCode]: {
197
+ window: 60,
198
+ max: options.signInPerMinute ?? 5
199
+ },
189
200
  [signUpPaths.create]: {
190
201
  window: 60,
191
202
  max: options.signInPerMinute ?? 5
@@ -215,7 +226,8 @@ const createAuth = (options) => {
215
226
  const signUpRole = options.signUp && checkSignUpRole(options.signUp.role, roles);
216
227
  const others = roles.filter((role) => role !== "admin");
217
228
  const defaultRole = options.defaultRole ?? (options.organizations ? "user" : others.length === 1 ? others[0] : void 0);
218
- const mailer = options.mailer === void 0 ? platformMailer() : options.mailer || void 0;
229
+ const appName = options.appName ?? platformAppName();
230
+ const mailer = options.mailer === void 0 ? platformMailer(void 0, appName) : options.mailer || void 0;
219
231
  const provider = options.operator === void 0 ? platformOperator() : options.operator || void 0;
220
232
  const operator = provider && resolveOperator(provider);
221
233
  const signInSettings = options.signInProvider === void 0 ? platformSignInSettings() : options.signInProvider || void 0;
@@ -232,6 +244,7 @@ const createAuth = (options) => {
232
244
  roles,
233
245
  definitions,
234
246
  defaultRole,
247
+ ...appName && { appName },
235
248
  mailer,
236
249
  signUpRole,
237
250
  operator,
@@ -1,7 +1,7 @@
1
1
  import "./role-definitions.js";
2
2
  import { checkAppRoleChange, effectiveRoles, globalRoles, parseAppRoles } from "./app-roles.js";
3
3
  import { findMember } from "./store.js";
4
- import { invitationEmail } from "./invitation-mail.js";
4
+ import { sendAuthEmail } from "../auth-mail/send-auth-email.js";
5
5
  import { invitationLink, invitationToken } from "./invitation-token.js";
6
6
  import { APIError } from "better-auth/api";
7
7
  import { organization } from "better-auth/plugins/organization";
@@ -63,7 +63,7 @@ const mergeHooks = (own, project = {}) => {
63
63
  * `creatorAppRoles`, invitations checked against what the inviter may give and mailed with a signed link, and the
64
64
  * project's hooks after Protobase's.
65
65
  */
66
- const organizationPlugin = ({ resolved, secret, mailer, context }) => {
66
+ const organizationPlugin = ({ resolved, secret, mail, context }) => {
67
67
  const { definitions } = resolved;
68
68
  const own = {
69
69
  beforeCreateOrganization: async () => ({ data: { id: await resolved.generateId() } }),
@@ -111,15 +111,15 @@ const organizationPlugin = ({ resolved, secret, mailer, context }) => {
111
111
  requireEmailVerificationOnInvitation: true,
112
112
  cancelPendingInvitationsOnReInvite: true,
113
113
  schema: organizationNames,
114
- ...mailer && { sendInvitationEmail: async ({ invitation, organization, inviter }) => {
114
+ ...mail && { sendInvitationEmail: async ({ invitation, organization, inviter }) => {
115
115
  const token = await invitationToken(secret, invitation);
116
- await mailer.send(invitationEmail({
117
- to: invitation.email,
116
+ const url = invitationLink(resolved.invitationUrl, token);
117
+ await sendAuthEmail(mail, "invitationEmail", invitation.email, {
118
118
  inviter: inviter.user.name || inviter.user.email,
119
119
  organization: organization.name,
120
- url: invitationLink(resolved.invitationUrl, token),
121
- expiresAt: invitation.expiresAt
122
- }));
120
+ url,
121
+ expiresAt: new Date(invitation.expiresAt)
122
+ }, url);
123
123
  } },
124
124
  organizationHooks: mergeHooks(own, resolved.options.hooks)
125
125
  });
@@ -1,32 +1,19 @@
1
+ import { sendAuthEmail } from "./auth-mail/send-auth-email.js";
1
2
  //#region src/better-auth/password-reset.ts
2
3
  /** How long an emailed reset link works, in seconds and in the email's words. */
3
4
  const resetLinkLifetimeSeconds = 3600;
4
5
  const resetLinkLifetime = "1 hour";
5
- /** The reset email: the link, how long it works, and that it can be ignored. */
6
- const resetEmail = ({ to, url }) => ({
7
- to,
8
- subject: "Reset your password",
9
- text: [
10
- "Someone asked to reset the password of your account. To choose a new password, open this link:",
11
- "",
12
- url,
13
- "",
14
- `The link works for ${resetLinkLifetime}, once.`,
15
- "If you did not ask for this, ignore this email: your password stays as it is.",
16
- ""
17
- ].join("\n")
18
- });
19
6
  /**
20
- * Better Auth's own password reset, sending the link with `mailer`. Resetting ends the user's sessions, so a reset
7
+ * Better Auth's own password reset, sending the link with `mail`. Resetting ends the user's sessions, so a reset
21
8
  * after a leaked password also signs out whoever used it.
22
9
  */
23
- const passwordResetOptions = (mailer) => ({
10
+ const passwordResetOptions = (mail) => ({
24
11
  resetPasswordTokenExpiresIn: resetLinkLifetimeSeconds,
25
12
  revokeSessionsOnPasswordReset: true,
26
- sendResetPassword: ({ user, url }) => mailer.send(resetEmail({
27
- to: user.email,
28
- url
29
- }))
13
+ sendResetPassword: ({ user, url }) => sendAuthEmail(mail, "resetPasswordEmail", user.email, {
14
+ url,
15
+ lifetime: resetLinkLifetime
16
+ }, url)
30
17
  });
31
18
  //#endregion
32
- export { passwordResetOptions, resetEmail, resetLinkLifetimeSeconds };
19
+ export { passwordResetOptions, resetLinkLifetimeSeconds };