better-auth 1.6.23 → 1.6.24
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/adapters/index.d.mts +1 -6
- package/dist/api/dispatch.d.mts +0 -1
- package/dist/api/index.d.mts +476 -478
- package/dist/api/middlewares/authorization.d.mts +12 -8
- package/dist/api/middlewares/authorization.mjs +2 -1
- package/dist/api/middlewares/index.d.mts +2 -1
- package/dist/api/middlewares/origin-check.d.mts +3 -5
- package/dist/api/routes/account.d.mts +10 -13
- package/dist/api/routes/account.mjs +35 -7
- package/dist/api/routes/callback.d.mts +1 -3
- package/dist/api/routes/callback.mjs +4 -0
- package/dist/api/routes/email-verification.d.mts +4 -8
- package/dist/api/routes/email-verification.mjs +15 -2
- package/dist/api/routes/error.d.mts +1 -3
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +1 -3
- package/dist/api/routes/password.d.mts +7 -9
- package/dist/api/routes/password.mjs +14 -1
- package/dist/api/routes/session.d.mts +22 -24
- package/dist/api/routes/session.mjs +5 -1
- package/dist/api/routes/sign-in.d.mts +3 -5
- package/dist/api/routes/sign-in.mjs +84 -2
- package/dist/api/routes/sign-out.d.mts +1 -3
- package/dist/api/routes/sign-up.d.mts +3 -4
- package/dist/api/routes/sign-up.mjs +3 -2
- package/dist/api/routes/update-session.d.mts +3 -4
- package/dist/api/routes/update-user.d.mts +13 -14
- package/dist/api/routes/update-user.mjs +26 -1
- package/dist/auth/full.d.mts +1 -1
- package/dist/auth/minimal.d.mts +1 -1
- package/dist/client/config.d.mts +12 -14
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +0 -1
- package/dist/client/index.d.mts +6 -5
- package/dist/client/lynx/index.d.mts +4 -5
- package/dist/client/lynx/lynx-store.d.mts +1 -2
- package/dist/client/parser.d.mts +7 -3
- package/dist/client/path-to-object.d.mts +3 -4
- package/dist/client/plugins/index.d.mts +1 -1
- package/dist/client/plugins/infer-plugin.d.mts +0 -1
- package/dist/client/query.d.mts +0 -1
- package/dist/client/query.mjs +38 -20
- package/dist/client/react/index.d.mts +4 -5
- package/dist/client/react/react-store.d.mts +1 -2
- package/dist/client/session-refresh.d.mts +0 -1
- package/dist/client/solid/index.d.mts +5 -6
- package/dist/client/svelte/index.d.mts +5 -6
- package/dist/client/types.d.mts +2 -2
- package/dist/client/vanilla.d.mts +2 -3
- package/dist/client/vue/index.d.mts +5 -6
- package/dist/context/create-context.mjs +3 -3
- package/dist/context/helpers.mjs +2 -2
- package/dist/cookies/cookie-utils.d.mts +1 -1
- package/dist/cookies/index.d.mts +6 -7
- package/dist/cookies/index.mjs +4 -0
- package/dist/cookies/session-store.d.mts +1 -0
- package/dist/cookies/session-store.mjs +6 -1
- package/dist/crypto/index.d.mts +2 -9
- package/dist/crypto/jwt.d.mts +0 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/db/adapter-base.d.mts +0 -1
- package/dist/db/adapter-kysely.d.mts +0 -1
- package/dist/db/field-converter.d.mts +0 -1
- package/dist/db/field.d.mts +9 -10
- package/dist/db/get-migration.d.mts +0 -1
- package/dist/db/get-migration.mjs +8 -4
- package/dist/db/get-schema.d.mts +0 -1
- package/dist/db/internal-adapter.d.mts +0 -1
- package/dist/db/internal-adapter.mjs +61 -1
- package/dist/db/revoke-unproven-account-access.d.mts +0 -1
- package/dist/db/schema.d.mts +2 -2
- package/dist/db/to-zod.d.mts +3 -7
- package/dist/db/with-hooks.d.mts +0 -1
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +4 -7
- package/dist/integrations/node.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +2 -9
- package/dist/integrations/tanstack-start-solid.d.mts +2 -5
- package/dist/integrations/tanstack-start.d.mts +2 -5
- package/dist/oauth2/link-account.d.mts +1 -1
- package/dist/oauth2/state.d.mts +0 -1
- package/dist/oauth2/utils.d.mts +0 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +0 -1
- package/dist/plugins/access/types.d.mts +4 -5
- package/dist/plugins/additional-fields/client.d.mts +0 -1
- package/dist/plugins/admin/access/statement.d.mts +1 -0
- package/dist/plugins/admin/admin.d.mts +120 -125
- package/dist/plugins/admin/client.d.mts +30 -30
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +23 -25
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/routes.mjs +9 -0
- package/dist/plugins/admin/schema.d.mts +1 -1
- package/dist/plugins/admin/types.d.mts +3 -2
- package/dist/plugins/anonymous/client.d.mts +9 -11
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +8 -10
- package/dist/plugins/anonymous/index.d.mts +14 -18
- package/dist/plugins/anonymous/types.d.mts +1 -1
- package/dist/plugins/bearer/index.d.mts +4 -7
- package/dist/plugins/captcha/index.d.mts +5 -8
- package/dist/plugins/captcha/types.d.mts +0 -1
- package/dist/plugins/custom-session/client.d.mts +0 -1
- package/dist/plugins/custom-session/index.d.mts +7 -12
- package/dist/plugins/device-authorization/client.d.mts +0 -1
- package/dist/plugins/device-authorization/index.d.mts +19 -22
- package/dist/plugins/email-otp/client.d.mts +4 -6
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +3 -5
- package/dist/plugins/email-otp/index.d.mts +67 -73
- package/dist/plugins/email-otp/routes.mjs +2 -0
- package/dist/plugins/email-otp/types.d.mts +0 -1
- package/dist/plugins/generic-oauth/client.d.mts +10 -11
- package/dist/plugins/generic-oauth/client.mjs +1 -1
- package/dist/plugins/generic-oauth/error-codes.d.mts +8 -10
- package/dist/plugins/generic-oauth/index.d.mts +40 -44
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +2 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/line.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/okta.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/slack.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +0 -1
- package/dist/plugins/generic-oauth/routes.mjs +14 -0
- package/dist/plugins/generic-oauth/types.d.mts +1 -2
- package/dist/plugins/haveibeenpwned/index.d.mts +3 -6
- package/dist/plugins/index.d.mts +4 -1
- package/dist/plugins/jwt/client.d.mts +2 -4
- package/dist/plugins/jwt/index.d.mts +8 -11
- package/dist/plugins/jwt/sign.d.mts +2 -2
- package/dist/plugins/jwt/types.d.mts +1 -1
- package/dist/plugins/jwt/utils.d.mts +2 -4
- package/dist/plugins/jwt/verify.d.mts +0 -1
- package/dist/plugins/last-login-method/client.mjs +13 -0
- package/dist/plugins/last-login-method/index.d.mts +11 -5
- package/dist/plugins/last-login-method/index.mjs +8 -0
- package/dist/plugins/magic-link/client.d.mts +0 -1
- package/dist/plugins/magic-link/index.d.mts +4 -5
- package/dist/plugins/magic-link/index.mjs +32 -1
- package/dist/plugins/mcp/authorize.mjs +12 -0
- package/dist/plugins/mcp/client/adapters.d.mts +0 -1
- package/dist/plugins/mcp/client/index.d.mts +2 -0
- package/dist/plugins/mcp/client/index.mjs +36 -11
- package/dist/plugins/mcp/index.d.mts +10 -11
- package/dist/plugins/multi-session/client.d.mts +2 -4
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +1 -3
- package/dist/plugins/multi-session/index.d.mts +7 -11
- package/dist/plugins/multi-session/index.mjs +45 -0
- package/dist/plugins/oauth-popup/client.d.mts +6 -12
- package/dist/plugins/oauth-popup/client.mjs +5 -3
- package/dist/plugins/oauth-popup/error-codes.d.mts +4 -6
- package/dist/plugins/oauth-popup/index.d.mts +8 -12
- package/dist/plugins/oauth-popup/index.mjs +1 -1
- package/dist/plugins/oauth-popup/types.d.mts +1 -2
- package/dist/plugins/oauth-proxy/index.d.mts +6 -9
- package/dist/plugins/oauth-proxy/index.mjs +2 -2
- package/dist/plugins/oidc-provider/authorize.mjs +9 -0
- package/dist/plugins/oidc-provider/client.d.mts +1 -2
- package/dist/plugins/oidc-provider/index.d.mts +15 -17
- package/dist/plugins/oidc-provider/index.mjs +26 -2
- package/dist/plugins/oidc-provider/schema.d.mts +0 -1
- package/dist/plugins/oidc-provider/schema.mjs +37 -0
- package/dist/plugins/oidc-provider/types.d.mts +1 -1
- package/dist/plugins/one-tap/client.d.mts +3 -6
- package/dist/plugins/one-tap/client.mjs +3 -0
- package/dist/plugins/one-tap/index.d.mts +1 -3
- package/dist/plugins/one-tap/index.mjs +5 -0
- package/dist/plugins/one-time-token/client.d.mts +1 -2
- package/dist/plugins/one-time-token/index.d.mts +5 -6
- package/dist/plugins/one-time-token/index.mjs +30 -0
- package/dist/plugins/open-api/generator.d.mts +0 -1
- package/dist/plugins/open-api/generator.mjs +81 -5
- package/dist/plugins/open-api/index.d.mts +3 -5
- package/dist/plugins/organization/access/statement.d.mts +1 -0
- package/dist/plugins/organization/adapter.d.mts +56 -82
- package/dist/plugins/organization/adapter.mjs +17 -3
- package/dist/plugins/organization/client.d.mts +106 -105
- package/dist/plugins/organization/client.mjs +7 -4
- package/dist/plugins/organization/error-codes.d.mts +59 -61
- package/dist/plugins/organization/has-permission.d.mts +0 -1
- package/dist/plugins/organization/has-permission.mjs +1 -1
- package/dist/plugins/organization/index.d.mts +1 -1
- package/dist/plugins/organization/organization.d.mts +7 -7
- package/dist/plugins/organization/organization.mjs +434 -1
- package/dist/plugins/organization/permission.d.mts +2 -2
- package/dist/plugins/organization/routes/crud-access-control.d.mts +17 -17
- package/dist/plugins/organization/routes/crud-invites.d.mts +53 -54
- package/dist/plugins/organization/routes/crud-invites.mjs +1 -1
- package/dist/plugins/organization/routes/crud-members.d.mts +44 -46
- package/dist/plugins/organization/routes/crud-members.mjs +4 -1
- package/dist/plugins/organization/routes/crud-org.d.mts +47 -48
- package/dist/plugins/organization/routes/crud-org.mjs +2 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +50 -51
- package/dist/plugins/organization/schema.d.mts +4 -4
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -16
- package/dist/plugins/phone-number/client.d.mts +13 -15
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +12 -14
- package/dist/plugins/phone-number/index.d.mts +41 -47
- package/dist/plugins/phone-number/routes.mjs +15 -0
- package/dist/plugins/phone-number/types.d.mts +1 -1
- package/dist/plugins/siwe/client.d.mts +0 -1
- package/dist/plugins/siwe/index.d.mts +4 -5
- package/dist/plugins/test-utils/index.d.mts +2 -4
- package/dist/plugins/test-utils/types.d.mts +1 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +4 -6
- package/dist/plugins/two-factor/backup-codes/index.mjs +52 -1
- package/dist/plugins/two-factor/client.d.mts +12 -15
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +10 -12
- package/dist/plugins/two-factor/index.d.mts +27 -31
- package/dist/plugins/two-factor/index.mjs +30 -0
- package/dist/plugins/two-factor/otp/index.d.mts +2 -4
- package/dist/plugins/two-factor/otp/index.mjs +42 -1
- package/dist/plugins/two-factor/totp/index.d.mts +4 -6
- package/dist/plugins/two-factor/totp/index.mjs +47 -0
- package/dist/plugins/two-factor/types.d.mts +1 -1
- package/dist/plugins/username/client.d.mts +9 -11
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +8 -10
- package/dist/plugins/username/index.d.mts +17 -22
- package/dist/plugins/username/schema.d.mts +3 -5
- package/dist/state.d.mts +0 -1
- package/dist/state.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +5 -3
- package/dist/test-utils/test-instance.mjs +4 -1
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +1 -2
- package/dist/types/auth.d.mts +0 -1
- package/dist/types/helper.d.mts +5 -5
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +0 -1
- package/dist/types/plugins.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/request.mjs +23 -0
- package/dist/utils/url.d.mts +0 -1
- package/package.json +10 -10
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import * as _better_auth_core0 from "@better-auth/core";
|
|
2
1
|
import { ClientFetchOption } from "@better-auth/core";
|
|
3
|
-
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
4
|
-
|
|
5
2
|
//#region src/plugins/one-tap/client.d.ts
|
|
6
3
|
declare global {
|
|
7
4
|
interface Window {
|
|
@@ -162,13 +159,13 @@ declare const oneTapClient: (options: GoogleOneTapOptions) => {
|
|
|
162
159
|
id: string;
|
|
163
160
|
name: string;
|
|
164
161
|
hooks: {
|
|
165
|
-
onResponse(ctx:
|
|
162
|
+
onResponse(ctx: import("@better-fetch/fetch").ResponseContext): Promise<void>;
|
|
166
163
|
};
|
|
167
164
|
}[];
|
|
168
|
-
getActions: ($fetch:
|
|
165
|
+
getActions: ($fetch: import("@better-fetch/fetch").BetterFetch, _: import("@better-auth/core").ClientStore) => {
|
|
169
166
|
oneTap: (opts?: GoogleOneTapActionOptions | undefined, fetchOptions?: ClientFetchOption | undefined) => Promise<void>;
|
|
170
167
|
};
|
|
171
|
-
getAtoms($fetch:
|
|
168
|
+
getAtoms($fetch: import("@better-fetch/fetch").BetterFetch): {};
|
|
172
169
|
};
|
|
173
170
|
//#endregion
|
|
174
171
|
export { GoogleOneTapActionOptions, GoogleOneTapOptions, GsiButtonConfiguration, oneTapClient };
|
|
@@ -124,6 +124,9 @@ const oneTapClient = (options) => {
|
|
|
124
124
|
context: contextValue,
|
|
125
125
|
ux_mode: opts?.uxMode || "popup",
|
|
126
126
|
nonce: opts?.nonce,
|
|
127
|
+
/**
|
|
128
|
+
* @see {@link https://developers.google.com/identity/gsi/web/guides/overview}
|
|
129
|
+
*/
|
|
127
130
|
itp_support: true,
|
|
128
131
|
use_fedcm_for_prompt: useFedCM,
|
|
129
132
|
...options.additionalOptions
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import * as better_call0 from "better-call";
|
|
2
1
|
import * as z from "zod";
|
|
3
|
-
|
|
4
2
|
//#region src/plugins/one-tap/index.d.ts
|
|
5
3
|
declare module "@better-auth/core" {
|
|
6
4
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -28,7 +26,7 @@ declare const oneTap: (options?: OneTapOptions | undefined) => {
|
|
|
28
26
|
id: "one-tap";
|
|
29
27
|
version: string;
|
|
30
28
|
endpoints: {
|
|
31
|
-
oneTapCallback:
|
|
29
|
+
oneTapCallback: import("better-call").StrictEndpoint<"/one-tap/callback", {
|
|
32
30
|
method: "POST";
|
|
33
31
|
body: z.ZodObject<{
|
|
34
32
|
idToken: z.ZodString;
|
|
@@ -10,6 +10,11 @@ import * as z from "zod";
|
|
|
10
10
|
//#region src/plugins/one-tap/index.ts
|
|
11
11
|
const oneTapCallbackBodySchema = z.object({
|
|
12
12
|
idToken: z.string().meta({ description: "Google ID token, which the client obtains from the One Tap API" }),
|
|
13
|
+
/**
|
|
14
|
+
* Sent so the global origin-check middleware validates the post-login
|
|
15
|
+
* redirect target against `trustedOrigins`. Without it the client performs
|
|
16
|
+
* an unvalidated `window.location` redirect, which is an open redirect.
|
|
17
|
+
*/
|
|
13
18
|
callbackURL: z.string().meta({ description: "URL to redirect to after a successful sign-in" }).optional()
|
|
14
19
|
});
|
|
15
20
|
const oneTap = (options) => ({
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { OneTimeTokenOptions, oneTimeToken } from "./index.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/plugins/one-time-token/client.d.ts
|
|
4
3
|
declare const oneTimeTokenClient: () => {
|
|
5
4
|
id: "one-time-token";
|
|
@@ -7,4 +6,4 @@ declare const oneTimeTokenClient: () => {
|
|
|
7
6
|
$InferServerPlugin: ReturnType<typeof oneTimeToken>;
|
|
8
7
|
};
|
|
9
8
|
//#endregion
|
|
10
|
-
export { oneTimeTokenClient };
|
|
9
|
+
export { type OneTimeTokenOptions, oneTimeTokenClient };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Session, User } from "../../types/models.mjs";
|
|
2
|
+
import "../../types/index.mjs";
|
|
2
3
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as better_call0 from "better-call";
|
|
4
4
|
import * as z from "zod";
|
|
5
|
-
|
|
6
5
|
//#region src/plugins/one-time-token/index.d.ts
|
|
7
6
|
declare module "@better-auth/core" {
|
|
8
7
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -67,9 +66,9 @@ declare const oneTimeToken: (options?: OneTimeTokenOptions | undefined) => {
|
|
|
67
66
|
*
|
|
68
67
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-generate)
|
|
69
68
|
*/
|
|
70
|
-
generateOneTimeToken:
|
|
69
|
+
generateOneTimeToken: import("better-call").StrictEndpoint<"/one-time-token/generate", {
|
|
71
70
|
method: "GET";
|
|
72
|
-
use: ((inputContext:
|
|
71
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
73
72
|
session: {
|
|
74
73
|
session: Record<string, any> & {
|
|
75
74
|
id: string;
|
|
@@ -110,7 +109,7 @@ declare const oneTimeToken: (options?: OneTimeTokenOptions | undefined) => {
|
|
|
110
109
|
*
|
|
111
110
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-verify)
|
|
112
111
|
*/
|
|
113
|
-
verifyOneTimeToken:
|
|
112
|
+
verifyOneTimeToken: import("better-call").StrictEndpoint<"/one-time-token/verify", {
|
|
114
113
|
method: "POST";
|
|
115
114
|
body: z.ZodObject<{
|
|
116
115
|
token: z.ZodString;
|
|
@@ -123,7 +122,7 @@ declare const oneTimeToken: (options?: OneTimeTokenOptions | undefined) => {
|
|
|
123
122
|
hooks: {
|
|
124
123
|
after: {
|
|
125
124
|
matcher: () => true;
|
|
126
|
-
handler: (inputContext:
|
|
125
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
127
126
|
}[];
|
|
128
127
|
};
|
|
129
128
|
options: OneTimeTokenOptions | undefined;
|
|
@@ -32,6 +32,21 @@ const oneTimeToken = (options) => {
|
|
|
32
32
|
id: "one-time-token",
|
|
33
33
|
version: PACKAGE_VERSION,
|
|
34
34
|
endpoints: {
|
|
35
|
+
/**
|
|
36
|
+
* ### Endpoint
|
|
37
|
+
*
|
|
38
|
+
* GET `/one-time-token/generate`
|
|
39
|
+
*
|
|
40
|
+
* ### API Methods
|
|
41
|
+
*
|
|
42
|
+
* **server:**
|
|
43
|
+
* `auth.api.generateOneTimeToken`
|
|
44
|
+
*
|
|
45
|
+
* **client:**
|
|
46
|
+
* `authClient.oneTimeToken.generate`
|
|
47
|
+
*
|
|
48
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-generate)
|
|
49
|
+
*/
|
|
35
50
|
generateOneTimeToken: createAuthEndpoint("/one-time-token/generate", {
|
|
36
51
|
method: "GET",
|
|
37
52
|
use: [sessionMiddleware]
|
|
@@ -41,6 +56,21 @@ const oneTimeToken = (options) => {
|
|
|
41
56
|
const token = await generateToken(c, session);
|
|
42
57
|
return c.json({ token });
|
|
43
58
|
}),
|
|
59
|
+
/**
|
|
60
|
+
* ### Endpoint
|
|
61
|
+
*
|
|
62
|
+
* POST `/one-time-token/verify`
|
|
63
|
+
*
|
|
64
|
+
* ### API Methods
|
|
65
|
+
*
|
|
66
|
+
* **server:**
|
|
67
|
+
* `auth.api.verifyOneTimeToken`
|
|
68
|
+
*
|
|
69
|
+
* **client:**
|
|
70
|
+
* `authClient.oneTimeToken.verify`
|
|
71
|
+
*
|
|
72
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/one-time-token#api-method-one-time-token-verify)
|
|
73
|
+
*/
|
|
44
74
|
verifyOneTimeToken: createAuthEndpoint("/one-time-token/verify", {
|
|
45
75
|
method: "POST",
|
|
46
76
|
body: verifyOneTimeTokenBodySchema
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AuthContext, BetterAuthOptions } from "@better-auth/core";
|
|
2
2
|
import { DBFieldAttributeConfig, DBFieldType } from "@better-auth/core/db";
|
|
3
3
|
import { OpenAPIParameter, OpenAPISchemaType } from "better-call";
|
|
4
|
-
|
|
5
4
|
//#region src/plugins/open-api/generator.d.ts
|
|
6
5
|
interface Path {
|
|
7
6
|
get?: OpenAPIOperation | undefined;
|
|
@@ -2,7 +2,7 @@ import { db_exports } from "../../db/index.mjs";
|
|
|
2
2
|
import { getEndpoints } from "../../api/index.mjs";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
//#region src/plugins/open-api/generator.ts
|
|
5
|
-
const OPEN_API_SCHEMA_TYPES = new Set([
|
|
5
|
+
const OPEN_API_SCHEMA_TYPES = /* @__PURE__ */ new Set([
|
|
6
6
|
"string",
|
|
7
7
|
"number",
|
|
8
8
|
"boolean",
|
|
@@ -47,7 +47,7 @@ function withDescription(schema, zodType) {
|
|
|
47
47
|
function addNullType(schema) {
|
|
48
48
|
if (schema.type) {
|
|
49
49
|
const type = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
50
|
-
const nullableType = Array.from(new Set([...type, "null"]));
|
|
50
|
+
const nullableType = Array.from(/* @__PURE__ */ new Set([...type, "null"]));
|
|
51
51
|
return {
|
|
52
52
|
...schema,
|
|
53
53
|
type: nullableType
|
|
@@ -134,7 +134,7 @@ function mergeObjectSchemas(left, right, description) {
|
|
|
134
134
|
if (properties[key] !== void 0 && !areSchemasEqual(properties[key], value)) return;
|
|
135
135
|
properties[key] = value;
|
|
136
136
|
}
|
|
137
|
-
const required = Array.from(new Set([...left.required || [], ...right.required || []]));
|
|
137
|
+
const required = Array.from(/* @__PURE__ */ new Set([...left.required || [], ...right.required || []]));
|
|
138
138
|
const leftAdditionalProperties = left.additionalProperties;
|
|
139
139
|
const rightAdditionalProperties = right.additionalProperties;
|
|
140
140
|
if (!areSchemaMembersCompatible(leftAdditionalProperties, rightAdditionalProperties)) return;
|
|
@@ -162,6 +162,82 @@ function getRequestBody(options) {
|
|
|
162
162
|
content: { "application/json": { schema } }
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Paths that accept `user.additionalFields` and plugin user schema fields via
|
|
167
|
+
* `parseUserInput`. Their static OpenAPI request bodies need those fields merged in.
|
|
168
|
+
*/
|
|
169
|
+
const USER_INPUT_BODY_PATHS = /* @__PURE__ */ new Set(["/sign-up/email", "/update-user"]);
|
|
170
|
+
function dbFieldToRequestBodyProperty(field) {
|
|
171
|
+
if (field.type === "date") return {
|
|
172
|
+
type: "string",
|
|
173
|
+
format: "date-time"
|
|
174
|
+
};
|
|
175
|
+
if (field.type === "json") return {
|
|
176
|
+
type: "object",
|
|
177
|
+
additionalProperties: true
|
|
178
|
+
};
|
|
179
|
+
if (field.type === "string[]") return {
|
|
180
|
+
type: "array",
|
|
181
|
+
items: { type: "string" }
|
|
182
|
+
};
|
|
183
|
+
if (field.type === "number[]") return {
|
|
184
|
+
type: "array",
|
|
185
|
+
items: { type: "number" }
|
|
186
|
+
};
|
|
187
|
+
if (Array.isArray(field.type)) return {
|
|
188
|
+
type: "string",
|
|
189
|
+
enum: field.type
|
|
190
|
+
};
|
|
191
|
+
const schema = { type: field.type };
|
|
192
|
+
if (field.defaultValue !== void 0 && typeof field.defaultValue !== "function") schema.default = field.defaultValue;
|
|
193
|
+
return schema;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Collect client-writable user fields from `user.additionalFields` and plugin
|
|
197
|
+
* schemas. Mirrors `getFields(..., "input")` used by `parseUserInput`.
|
|
198
|
+
*/
|
|
199
|
+
function getUserInputRequestBodyFields(options) {
|
|
200
|
+
let fields = { ...options.user?.additionalFields ?? {} };
|
|
201
|
+
for (const plugin of options.plugins || []) {
|
|
202
|
+
const pluginUserFields = plugin.schema?.user?.fields;
|
|
203
|
+
if (pluginUserFields) fields = {
|
|
204
|
+
...fields,
|
|
205
|
+
...pluginUserFields
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
const properties = {};
|
|
209
|
+
const required = [];
|
|
210
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
211
|
+
if (!field || field.input === false) continue;
|
|
212
|
+
properties[key] = dbFieldToRequestBodyProperty(field);
|
|
213
|
+
if (field.required === true && field.defaultValue === void 0) required.push(key);
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
properties,
|
|
217
|
+
required
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function applyUserInputFieldsToRequestBody(path, requestBody, options) {
|
|
221
|
+
if (!USER_INPUT_BODY_PATHS.has(path)) return requestBody;
|
|
222
|
+
const { properties: inputProperties, required: inputRequired } = getUserInputRequestBodyFields(options);
|
|
223
|
+
if (Object.keys(inputProperties).length === 0) return requestBody;
|
|
224
|
+
const existingSchema = requestBody?.content?.["application/json"]?.schema;
|
|
225
|
+
const properties = { ...existingSchema?.properties ?? {} };
|
|
226
|
+
for (const [key, value] of Object.entries(inputProperties)) if (properties[key] === void 0) properties[key] = value;
|
|
227
|
+
const required = new Set(existingSchema?.required ?? []);
|
|
228
|
+
if (path === "/sign-up/email") {
|
|
229
|
+
for (const key of inputRequired) if (properties[key] !== void 0) required.add(key);
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
...requestBody,
|
|
233
|
+
content: { "application/json": { schema: {
|
|
234
|
+
...existingSchema ?? {},
|
|
235
|
+
type: existingSchema?.type ?? "object",
|
|
236
|
+
properties,
|
|
237
|
+
...required.size > 0 ? { required: Array.from(required) } : {}
|
|
238
|
+
} } }
|
|
239
|
+
};
|
|
240
|
+
}
|
|
165
241
|
function toOpenApiSchema(zodType) {
|
|
166
242
|
if (zodType instanceof z.ZodOptional) return toOpenApiSchema(unwrapZodSchema(zodType));
|
|
167
243
|
if (zodType instanceof z.ZodNullable) return addNullType(toOpenApiSchema(unwrapZodSchema(zodType)));
|
|
@@ -323,7 +399,7 @@ async function generator(ctx, options) {
|
|
|
323
399
|
const components = { schemas: { ...Object.entries(tables).reduce((acc, [key, value]) => {
|
|
324
400
|
const modelName = key.charAt(0).toUpperCase() + key.slice(1);
|
|
325
401
|
const fields = value.fields;
|
|
326
|
-
const required = new Set(["id"]);
|
|
402
|
+
const required = /* @__PURE__ */ new Set(["id"]);
|
|
327
403
|
const properties = { id: {
|
|
328
404
|
type: "string",
|
|
329
405
|
readOnly: true
|
|
@@ -366,7 +442,7 @@ async function generator(ctx, options) {
|
|
|
366
442
|
}
|
|
367
443
|
};
|
|
368
444
|
for (const method of methods.filter((m) => m === "POST" || m === "PATCH" || m === "PUT")) {
|
|
369
|
-
const body = getRequestBody(options);
|
|
445
|
+
const body = applyUserInputFieldsToRequestBody(value.path, getRequestBody(options), ctx.options);
|
|
370
446
|
paths[path] = {
|
|
371
447
|
...paths[path],
|
|
372
448
|
[method.toLowerCase()]: {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { FieldSchema, OpenAPIModelSchema, OpenAPIParameter, OpenAPISchema, Path, generator } from "./generator.mjs";
|
|
2
2
|
import { LiteralString } from "@better-auth/core";
|
|
3
|
-
import * as better_call0 from "better-call";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/open-api/index.d.ts
|
|
6
4
|
declare module "@better-auth/core" {
|
|
7
5
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -44,7 +42,7 @@ declare const openAPI: <O extends OpenAPIOptions>(options?: O | undefined) => {
|
|
|
44
42
|
id: "open-api";
|
|
45
43
|
version: string;
|
|
46
44
|
endpoints: {
|
|
47
|
-
generateOpenAPISchema:
|
|
45
|
+
generateOpenAPISchema: import("better-call").StrictEndpoint<"/open-api/generate-schema", {
|
|
48
46
|
method: "GET";
|
|
49
47
|
}, {
|
|
50
48
|
openapi: string;
|
|
@@ -84,7 +82,7 @@ declare const openAPI: <O extends OpenAPIOptions>(options?: O | undefined) => {
|
|
|
84
82
|
}[];
|
|
85
83
|
paths: Record<string, Path>;
|
|
86
84
|
}>;
|
|
87
|
-
openAPIReference:
|
|
85
|
+
openAPIReference: import("better-call").StrictEndpoint<LiteralString | "/reference", {
|
|
88
86
|
method: "GET";
|
|
89
87
|
metadata: {
|
|
90
88
|
readonly scope: "server";
|
|
@@ -94,4 +92,4 @@ declare const openAPI: <O extends OpenAPIOptions>(options?: O | undefined) => {
|
|
|
94
92
|
options: NoInfer<O>;
|
|
95
93
|
};
|
|
96
94
|
//#endregion
|
|
97
|
-
export { type FieldSchema, type OpenAPIModelSchema, OpenAPIOptions, OpenAPIParameter, OpenAPISchema, type Path, generator, openAPI };
|
|
95
|
+
export { type FieldSchema, type OpenAPIModelSchema, OpenAPIOptions, type OpenAPIParameter, type OpenAPISchema, type Path, type generator, openAPI };
|