@protobase/server 0.46.10 → 0.46.12
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/dist/better-auth/auth-logger.js +11 -0
- package/dist/better-auth/auth-mail/change-email-code-email.js +1 -1
- package/dist/better-auth/auth-mail/sign-in-code-email.js +1 -1
- package/dist/better-auth/auth-mail/sign-up-code-email.js +1 -1
- package/dist/better-auth/auth-mail/two-factor-code-email.js +1 -1
- package/dist/better-auth/cookie-prefix.js +9 -0
- package/dist/better-auth/create-auth.d.ts +2 -0
- package/dist/better-auth/create-auth.js +4 -0
- package/dist/better-auth/sign-in-mail.js +3 -3
- package/dist/better-auth/sign-up/sign-up-code.js +2 -2
- package/dist/better-auth/users.js +4 -1
- package/dist/package.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createLogger } from "better-auth";
|
|
2
|
+
//#region src/better-auth/auth-logger.ts
|
|
3
|
+
const schemaReports = [/^Database schema mismatch/, /^Could not validate the database schema/];
|
|
4
|
+
const output = createLogger();
|
|
5
|
+
/** Better Auth's logger, without its reports on the store's schema. */
|
|
6
|
+
const authLogger = { log: (level, message, ...args) => {
|
|
7
|
+
if (schemaReports.some((report) => report.test(message))) return;
|
|
8
|
+
output[level](message, ...args);
|
|
9
|
+
} };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { authLogger };
|
|
@@ -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 }) =>
|
|
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 }) =>
|
|
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 }) =>
|
|
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 }) =>
|
|
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 };
|
|
@@ -8748,6 +8748,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
|
|
|
8748
8748
|
generateId: "uuid";
|
|
8749
8749
|
} | undefined;
|
|
8750
8750
|
useSecureCookies: boolean;
|
|
8751
|
+
cookiePrefix: string;
|
|
8751
8752
|
defaultCookieAttributes: {
|
|
8752
8753
|
sameSite: "lax";
|
|
8753
8754
|
secure: boolean;
|
|
@@ -8759,6 +8760,7 @@ export declare const createAuth: (options: CreateAuthOptions) => import("better-
|
|
|
8759
8760
|
socialProviders?: import("better-auth").SocialProviders | undefined;
|
|
8760
8761
|
appName: string;
|
|
8761
8762
|
database: any;
|
|
8763
|
+
logger: import("better-auth").Logger;
|
|
8762
8764
|
baseURL: string | {
|
|
8763
8765
|
allowedHosts: string[];
|
|
8764
8766
|
fallback: string;
|
|
@@ -7,6 +7,8 @@ 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 { authLogger } from "./auth-logger.js";
|
|
11
|
+
import { cookiePrefixOf } from "./cookie-prefix.js";
|
|
10
12
|
import { mobileRequests } from "./mobile-requests.js";
|
|
11
13
|
import { passwordLength } from "./new-account-password.js";
|
|
12
14
|
import { platformMailer } from "../mail/platform-mailer.js";
|
|
@@ -132,6 +134,7 @@ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, defini
|
|
|
132
134
|
return {
|
|
133
135
|
appName,
|
|
134
136
|
database: options.database,
|
|
137
|
+
logger: authLogger,
|
|
135
138
|
baseURL: multiHostBaseURL(options.baseURL, origins),
|
|
136
139
|
basePath: authBasePath,
|
|
137
140
|
secret: options.secret,
|
|
@@ -297,6 +300,7 @@ const betterAuthOptions = (options, { origins = [], passkeyDomain, roles, defini
|
|
|
297
300
|
},
|
|
298
301
|
advanced: {
|
|
299
302
|
useSecureCookies: secure,
|
|
303
|
+
cookiePrefix: cookiePrefixOf(options.baseURL),
|
|
300
304
|
defaultCookieAttributes: {
|
|
301
305
|
sameSite: "lax",
|
|
302
306
|
secure
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sendAuthEmail } from "./auth-mail/send-auth-email.js";
|
|
2
|
-
const codeLifetimeMinutes =
|
|
3
|
-
const codeLifetime = "
|
|
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:
|
|
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 = "
|
|
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() +
|
|
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)
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.12",
|
|
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.
|
|
40
|
-
"@protobase/query": "0.46.
|
|
41
|
-
"@protobase/schema": "0.46.
|
|
39
|
+
"@protobase/layout": "0.46.12",
|
|
40
|
+
"@protobase/query": "0.46.12",
|
|
41
|
+
"@protobase/schema": "0.46.12",
|
|
42
42
|
"@react-email/render": "^2.1.0",
|
|
43
43
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
44
44
|
"@sentry/core": "^11.7.0",
|