@protobase/server 0.46.10 → 0.46.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.
@@ -25,7 +25,7 @@ const ChangeEmailCodeEmail = ({ app, code, lifetime }) => /* @__PURE__ */ jsxs(E
25
25
  /** The email to the new address with the code that moves the account to it. */
26
26
  const changeEmailCodeEmail = defineEmail({
27
27
  name: "change-email-code",
28
- subject: ({ app }) => `Confirm your new ${app.name} address`,
28
+ subject: ({ app, code }) => `${code} confirms your new ${app.name} address`,
29
29
  component: ChangeEmailCodeEmail
30
30
  });
31
31
  //#endregion
@@ -25,7 +25,7 @@ const SignInCodeEmail = ({ app, code, lifetime }) => /* @__PURE__ */ jsxs(EmailL
25
25
  /** The email with a code to sign in with instead of a password. */
26
26
  const signInCodeEmail = defineEmail({
27
27
  name: "sign-in-code",
28
- subject: ({ app }) => `Your ${app.name} sign-in code`,
28
+ subject: ({ app, code }) => `${code} is your ${app.name} sign-in code`,
29
29
  component: SignInCodeEmail
30
30
  });
31
31
  //#endregion
@@ -25,7 +25,7 @@ const SignUpCodeEmail = ({ app, code, lifetime }) => /* @__PURE__ */ jsxs(EmailL
25
25
  /** The email with the code that makes an account for the address. */
26
26
  const signUpCodeEmail = defineEmail({
27
27
  name: "sign-up-code",
28
- subject: ({ app }) => `Your code to create an account with ${app.name}`,
28
+ subject: ({ app, code }) => `${code} is your code to create an account with ${app.name}`,
29
29
  component: SignUpCodeEmail
30
30
  });
31
31
  //#endregion
@@ -25,7 +25,7 @@ const TwoFactorCodeEmail = ({ app, code, lifetime }) => /* @__PURE__ */ jsxs(Ema
25
25
  /** The email with the second step of a sign-in, for an account with two-factor authentication by email. */
26
26
  const twoFactorCodeEmail = defineEmail({
27
27
  name: "two-factor-code",
28
- subject: ({ app }) => `Your ${app.name} verification code`,
28
+ subject: ({ app, code }) => `${code} is your ${app.name} verification code`,
29
29
  component: TwoFactorCodeEmail
30
30
  });
31
31
  //#endregion
@@ -0,0 +1,9 @@
1
+ //#region src/better-auth/cookie-prefix.ts
2
+ /** The prefix of the app's cookie names: Better Auth's own, with the port of an http `baseURL` that names one. */
3
+ const cookiePrefixOf = (baseURL) => {
4
+ const { protocol, port } = new URL(baseURL);
5
+ if (protocol !== "http:" || !port) return "better-auth";
6
+ return `better-auth-${port}`;
7
+ };
8
+ //#endregion
9
+ export { cookiePrefixOf };
@@ -1705,7 +1705,17 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
1705
1705
  email: string;
1706
1706
  emailVerified: boolean;
1707
1707
  name: string;
1708
- image?: string | null | undefined;
1708
+ image?
1709
+ /**
1710
+ * Refuses a new password that appears in a known data breach, by Have I Been Pwned's password list: at sign-up, from
1711
+ * an invitation, and when a password is set, changed, reset or given by an admin. Only the first five characters of
1712
+ * the password's SHA-1 hash leave the server. While the list cannot be reached, setting a password fails. Default off.
1713
+ */
1714
+ /**
1715
+ * Refuses a new password that appears in a known data breach, by Have I Been Pwned's password list: at sign-up, from
1716
+ * an invitation, and when a password is set, changed, reset or given by an admin. Only the first five characters of
1717
+ * the password's SHA-1 hash leave the server. While the list cannot be reached, setting a password fails. Default off.
1718
+ */ : string | null | undefined;
1709
1719
  }) | import("better-auth/plugins").UserWithTwoFactor;
1710
1720
  }>;
1711
1721
  generateBackupCodes: import("better-call").StrictEndpoint<"/two-factor/generate-backup-codes", {
@@ -3771,7 +3781,15 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
3771
3781
  userId: string;
3772
3782
  expiresAt: Date;
3773
3783
  token: string;
3774
- ipAddress?: string | null | undefined;
3784
+ ipAddress?
3785
+ /**
3786
+ * What runs when a user is deleted: `set` a named listener that removes what the app keeps of the user elsewhere,
3787
+ * such as their devices; `run` is for a deletion outside Better Auth's endpoints (`deleteUser`).
3788
+ */
3789
+ /**
3790
+ * What runs when a user is deleted: `set` a named listener that removes what the app keeps of the user elsewhere,
3791
+ * such as their devices; `run` is for a deletion outside Better Auth's endpoints (`deleteUser`).
3792
+ */ : string | null | undefined;
3775
3793
  userAgent?: string | null | undefined;
3776
3794
  };
3777
3795
  user: Record<string, any> & {
@@ -8748,6 +8766,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
8748
8766
  generateId: "uuid";
8749
8767
  } | undefined;
8750
8768
  useSecureCookies: boolean;
8769
+ cookiePrefix: string;
8751
8770
  defaultCookieAttributes: {
8752
8771
  sameSite: "lax";
8753
8772
  secure: boolean;
@@ -7,6 +7,7 @@ import { signInPolicyPlugin } from "./policy-plugin.js";
7
7
  import { goTrueSessionsPlugin } from "../gotrue/sessions-plugin.js";
8
8
  import { endReplacedSession } from "./end-replaced-session.js";
9
9
  import { authBasePath } from "./auth-base-path.js";
10
+ import { cookiePrefixOf } from "./cookie-prefix.js";
10
11
  import { mobileRequests } from "./mobile-requests.js";
11
12
  import { passwordLength } from "./new-account-password.js";
12
13
  import { platformMailer } from "../mail/platform-mailer.js";
@@ -297,6 +298,7 @@ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, defini
297
298
  },
298
299
  advanced: {
299
300
  useSecureCookies: secure,
301
+ cookiePrefix: cookiePrefixOf(options.baseURL),
300
302
  defaultCookieAttributes: {
301
303
  sameSite: "lax",
302
304
  secure
@@ -1,6 +1,6 @@
1
1
  import { sendAuthEmail } from "./auth-mail/send-auth-email.js";
2
- const codeLifetimeMinutes = 5;
3
- const codeLifetime = "5 minutes";
2
+ const codeLifetimeMinutes = 10;
3
+ const codeLifetime = "10 minutes";
4
4
  /**
5
5
  * Better Auth's email OTP plugin for signing in and changing the address: never a sign-up, codes stored hashed, sent
6
6
  * with `mail`. A new address gets its own email, with the code that moves the account to it. The plugin's other uses
@@ -8,7 +8,7 @@ const codeLifetime = "5 minutes";
8
8
  */
9
9
  const emailCodeOptions = (mail) => ({
10
10
  disableSignUp: true,
11
- expiresIn: 300,
11
+ expiresIn: 600,
12
12
  storeOTP: "hashed",
13
13
  changeEmail: { enabled: true },
14
14
  sendVerificationOTP: ({ email, otp, type }, ctx) => sendAuthEmail(mail, type === "change-email" ? "changeEmailCodeEmail" : "signInCodeEmail", email, {
@@ -1,5 +1,5 @@
1
1
  import { APIError } from "better-auth/api";
2
- const signUpCodeLifetime = "5 minutes";
2
+ const signUpCodeLifetime = "10 minutes";
3
3
  const allowedAttempts = 3;
4
4
  const identifierOf = (email) => `sign-up-otp-${email}`;
5
5
  /** The SHA-256 of `secret`, base64: what the store keeps of a code or a ticket. */
@@ -26,7 +26,7 @@ const issueSignUpCode = async (context, email) => {
26
26
  await context.internalAdapter.createVerificationValue({
27
27
  identifier,
28
28
  value: `${await hashOf(code)}:0`,
29
- expiresAt: new Date(Date.now() + 3e5)
29
+ expiresAt: new Date(Date.now() + 6e5)
30
30
  });
31
31
  return code;
32
32
  };
@@ -30,7 +30,10 @@ const checkAccounts = async (auth, accounts) => {
30
30
  const createUser = async (auth, input) => {
31
31
  const first = !await hasUsers(auth);
32
32
  const requested = input.role ?? auth.defaultRole;
33
- if (!first && requested === void 0) throw new Error(`A role is required: choose one of ${auth.roles.join(", ")}`);
33
+ if (!first && requested === void 0) {
34
+ if (await (await auth.$context).internalAdapter.findUserByEmail(input.email.toLowerCase())) throw new Error(`A user with email ${input.email} exists already; use another email`);
35
+ throw new Error(`A role is required: choose one of ${auth.roles.join(", ")}`);
36
+ }
34
37
  const role = first ? "admin" : checkRoles(auth, requested).join(",");
35
38
  const accounts = input.accounts ?? [];
36
39
  await checkAccounts(auth, accounts);
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.46.10";
2
+ var version = "0.46.11";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/server",
3
- "version": "0.46.10",
3
+ "version": "0.46.11",
4
4
  "description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -36,9 +36,9 @@
36
36
  "@better-auth/passkey": "^1.7.12",
37
37
  "@better-auth/sso": "^1.7.12",
38
38
  "@modelcontextprotocol/server": "^2.3.1",
39
- "@protobase/layout": "0.46.10",
40
- "@protobase/query": "0.46.10",
41
- "@protobase/schema": "0.46.10",
39
+ "@protobase/layout": "0.46.11",
40
+ "@protobase/query": "0.46.11",
41
+ "@protobase/schema": "0.46.11",
42
42
  "@react-email/render": "^2.1.0",
43
43
  "@scalar/hono-api-reference": "^0.12.10",
44
44
  "@sentry/core": "^11.7.0",