better-auth 1.7.12 → 1.7.13
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 +5 -10
- package/dist/api/dispatch.d.mts +3 -5
- package/dist/api/dispatch.mjs +6 -4
- package/dist/api/index.d.mts +506 -508
- package/dist/api/index.mjs +35 -34
- package/dist/api/middlewares/authorization.d.mts +15 -12
- 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 +4 -7
- package/dist/api/routes/account.d.mts +11 -15
- package/dist/api/routes/account.mjs +7 -4
- package/dist/api/routes/callback.d.mts +2 -5
- package/dist/api/routes/callback.mjs +4 -2
- package/dist/api/routes/email-verification.d.mts +7 -12
- package/dist/api/routes/error.d.mts +2 -5
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +2 -5
- package/dist/api/routes/password.d.mts +8 -11
- package/dist/api/routes/password.mjs +3 -2
- package/dist/api/routes/session.d.mts +26 -29
- package/dist/api/routes/sign-in.d.mts +4 -6
- package/dist/api/routes/sign-out.d.mts +2 -5
- package/dist/api/routes/sign-up.d.mts +4 -6
- package/dist/api/routes/update-session.d.mts +4 -6
- package/dist/api/routes/update-user.d.mts +14 -16
- package/dist/api/routes/update-user.mjs +1 -1
- package/dist/api/state/oauth.d.mts +0 -3
- package/dist/api/state/oauth.mjs +2 -1
- package/dist/auth/full.d.mts +3 -4
- package/dist/auth/minimal.d.mts +3 -3
- package/dist/client/broadcast-channel.d.mts +6 -7
- package/dist/client/config.d.mts +15 -19
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +3 -5
- package/dist/client/focus-manager.d.mts +4 -5
- package/dist/client/index.d.mts +8 -7
- package/dist/client/lynx/index.d.mts +6 -7
- package/dist/client/lynx/index.mjs +3 -2
- package/dist/client/lynx/lynx-store.d.mts +3 -4
- package/dist/client/online-manager.d.mts +4 -5
- package/dist/client/parser.d.mts +9 -5
- package/dist/client/path-to-object.d.mts +13 -14
- package/dist/client/plugins/index.d.mts +1 -1
- package/dist/client/plugins/infer-plugin.d.mts +2 -4
- package/dist/client/query.d.mts +4 -6
- package/dist/client/react/index.d.mts +6 -7
- package/dist/client/react/index.mjs +3 -2
- package/dist/client/react/react-store.d.mts +3 -4
- package/dist/client/session-atom.d.mts +4 -4
- package/dist/client/session-refresh.d.mts +3 -5
- package/dist/client/solid/index.d.mts +6 -7
- package/dist/client/solid/index.mjs +3 -2
- package/dist/client/svelte/index.d.mts +6 -7
- package/dist/client/svelte/index.mjs +3 -2
- package/dist/client/types.d.mts +11 -11
- package/dist/client/vanilla.d.mts +4 -5
- package/dist/client/vanilla.mjs +3 -2
- package/dist/client/vue/index.d.mts +6 -7
- package/dist/client/vue/index.mjs +3 -2
- package/dist/context/create-context.mjs +7 -7
- package/dist/context/helpers.mjs +9 -7
- package/dist/cookies/cookie-utils.d.mts +13 -13
- package/dist/cookies/cookie-utils.mjs +1 -3
- package/dist/cookies/index.d.mts +17 -18
- package/dist/cookies/index.mjs +11 -7
- package/dist/cookies/jwt.mjs +2 -1
- package/dist/cookies/session-store.d.mts +6 -5
- package/dist/cookies/session-store.mjs +3 -2
- package/dist/crypto/buffer.d.mts +2 -3
- package/dist/crypto/index.d.mts +9 -16
- package/dist/crypto/index.mjs +2 -1
- package/dist/crypto/jwt.d.mts +5 -7
- package/dist/crypto/jwt.mjs +2 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/crypto/random.d.mts +2 -3
- package/dist/db/adapter-base.d.mts +2 -4
- package/dist/db/adapter-kysely.d.mts +2 -4
- package/dist/db/field-converter.d.mts +3 -5
- package/dist/db/field.d.mts +11 -12
- package/dist/db/get-migration.d.mts +4 -8
- package/dist/db/get-migration.mjs +22 -22
- package/dist/db/get-schema.d.mts +2 -4
- package/dist/db/internal-adapter.d.mts +2 -4
- package/dist/db/internal-adapter.mjs +6 -4
- package/dist/db/revoke-unproven-account-access.d.mts +3 -4
- package/dist/db/schema.d.mts +15 -16
- package/dist/db/schema.mjs +6 -3
- package/dist/db/to-zod.d.mts +5 -9
- package/dist/db/with-hooks.d.mts +3 -5
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +7 -11
- package/dist/integrations/node.d.mts +5 -7
- package/dist/integrations/node.mjs +4 -2
- package/dist/integrations/solid-start.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +6 -14
- package/dist/integrations/tanstack-start-solid.d.mts +4 -8
- package/dist/integrations/tanstack-start.d.mts +4 -8
- package/dist/oauth2/link-account.d.mts +5 -11
- package/dist/oauth2/link-account.mjs +12 -6
- package/dist/oauth2/state.d.mts +5 -7
- package/dist/oauth2/state.mjs +1 -1
- package/dist/oauth2/utils.d.mts +4 -6
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +4 -6
- package/dist/plugins/access/index.mjs +1 -2
- package/dist/plugins/access/types.d.mts +12 -14
- package/dist/plugins/additional-fields/client.d.mts +2 -4
- package/dist/plugins/admin/access/index.mjs +1 -2
- package/dist/plugins/admin/access/statement.d.mts +7 -7
- package/dist/plugins/admin/admin.d.mts +122 -128
- package/dist/plugins/admin/client.d.mts +32 -32
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +25 -28
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/index.mjs +1 -2
- package/dist/plugins/admin/schema.d.mts +3 -4
- package/dist/plugins/admin/types.d.mts +8 -8
- package/dist/plugins/anonymous/client.d.mts +10 -12
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +10 -13
- package/dist/plugins/anonymous/index.d.mts +17 -21
- package/dist/plugins/anonymous/schema.d.mts +2 -3
- package/dist/plugins/anonymous/types.d.mts +5 -6
- package/dist/plugins/bearer/index.d.mts +7 -11
- package/dist/plugins/captcha/constants.d.mts +2 -3
- package/dist/plugins/captcha/index.d.mts +6 -9
- package/dist/plugins/captcha/types.d.mts +11 -13
- package/dist/plugins/custom-session/client.d.mts +2 -4
- package/dist/plugins/custom-session/index.d.mts +10 -16
- package/dist/plugins/device-authorization/client.d.mts +2 -4
- package/dist/plugins/device-authorization/index.d.mts +39 -44
- package/dist/plugins/device-authorization/index.mjs +10 -9
- package/dist/plugins/device-authorization/routes.d.mts +7 -5
- package/dist/plugins/device-authorization/routes.mjs +6 -5
- package/dist/plugins/device-authorization/schema.d.mts +2 -3
- package/dist/plugins/email-otp/client.d.mts +5 -7
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +5 -8
- package/dist/plugins/email-otp/index.d.mts +69 -76
- package/dist/plugins/email-otp/otp-token.mjs +19 -7
- package/dist/plugins/email-otp/types.d.mts +2 -4
- package/dist/plugins/generic-oauth/index.d.mts +9 -13
- package/dist/plugins/generic-oauth/index.mjs +6 -4
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +2 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +2 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/line.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/okta.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/slack.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +3 -5
- package/dist/plugins/generic-oauth/types.d.mts +6 -7
- package/dist/plugins/haveibeenpwned/index.d.mts +7 -11
- package/dist/plugins/index.d.mts +4 -1
- package/dist/plugins/jwt/client.d.mts +2 -3
- package/dist/plugins/jwt/index.d.mts +11 -14
- package/dist/plugins/jwt/index.mjs +1 -1
- package/dist/plugins/jwt/schema.d.mts +2 -3
- package/dist/plugins/jwt/sign.d.mts +9 -8
- package/dist/plugins/jwt/types.d.mts +7 -8
- package/dist/plugins/jwt/utils.d.mts +6 -9
- package/dist/plugins/jwt/verify.d.mts +2 -4
- package/dist/plugins/last-login-method/client.d.mts +3 -4
- package/dist/plugins/last-login-method/index.d.mts +5 -9
- package/dist/plugins/last-login-method/index.mjs +1 -1
- package/dist/plugins/magic-link/client.d.mts +2 -4
- package/dist/plugins/magic-link/index.d.mts +7 -10
- package/dist/plugins/magic-link/index.mjs +20 -17
- package/dist/plugins/multi-session/client.d.mts +3 -5
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +3 -6
- package/dist/plugins/multi-session/index.d.mts +10 -14
- package/dist/plugins/oauth-popup/client.d.mts +11 -17
- package/dist/plugins/oauth-popup/client.mjs +6 -4
- package/dist/plugins/oauth-popup/constants.d.mts +5 -6
- package/dist/plugins/oauth-popup/error-codes.d.mts +6 -9
- package/dist/plugins/oauth-popup/index.d.mts +11 -15
- package/dist/plugins/oauth-popup/index.mjs +8 -7
- package/dist/plugins/oauth-popup/types.d.mts +4 -6
- package/dist/plugins/oauth-proxy/index.d.mts +11 -15
- package/dist/plugins/oauth-proxy/index.mjs +10 -7
- package/dist/plugins/one-tap/client.d.mts +6 -9
- package/dist/plugins/one-tap/index.d.mts +4 -7
- package/dist/plugins/one-time-token/client.d.mts +2 -3
- package/dist/plugins/one-time-token/index.d.mts +8 -10
- package/dist/plugins/open-api/generator.d.mts +8 -8
- package/dist/plugins/open-api/generator.mjs +5 -5
- package/dist/plugins/open-api/index.d.mts +5 -7
- package/dist/plugins/organization/access/index.mjs +1 -2
- package/dist/plugins/organization/access/statement.d.mts +8 -8
- package/dist/plugins/organization/adapter.d.mts +60 -87
- package/dist/plugins/organization/adapter.mjs +14 -10
- package/dist/plugins/organization/client.d.mts +108 -107
- package/dist/plugins/organization/client.mjs +9 -5
- package/dist/plugins/organization/error-codes.d.mts +61 -64
- package/dist/plugins/organization/has-permission.d.mts +2 -4
- 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 +20 -20
- package/dist/plugins/organization/organization.mjs +13 -8
- package/dist/plugins/organization/permission.d.mts +4 -5
- package/dist/plugins/organization/routes/crud-access-control.d.mts +28 -28
- package/dist/plugins/organization/routes/crud-invites.d.mts +64 -65
- package/dist/plugins/organization/routes/crud-invites.mjs +21 -18
- package/dist/plugins/organization/routes/crud-members.d.mts +53 -56
- package/dist/plugins/organization/routes/crud-members.mjs +23 -21
- package/dist/plugins/organization/routes/crud-org.d.mts +63 -65
- package/dist/plugins/organization/routes/crud-org.mjs +4 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +65 -66
- package/dist/plugins/organization/routes/crud-team.mjs +4 -2
- package/dist/plugins/organization/schema.d.mts +33 -33
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -17
- package/dist/plugins/phone-number/client.d.mts +14 -16
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +14 -17
- package/dist/plugins/phone-number/index.d.mts +48 -54
- package/dist/plugins/phone-number/schema.d.mts +2 -3
- package/dist/plugins/phone-number/types.d.mts +4 -5
- package/dist/plugins/siwe/client.d.mts +2 -4
- package/dist/plugins/siwe/index.d.mts +7 -9
- package/dist/plugins/siwe/index.mjs +1 -1
- package/dist/plugins/siwe/parse-message.mjs +1 -3
- package/dist/plugins/siwe/schema.d.mts +3 -4
- package/dist/plugins/siwe/types.d.mts +4 -4
- package/dist/plugins/test-utils/auth-helpers.mjs +4 -2
- package/dist/plugins/test-utils/index.d.mts +3 -5
- package/dist/plugins/test-utils/types.d.mts +7 -7
- package/dist/plugins/two-factor/backup-codes/index.d.mts +11 -14
- package/dist/plugins/two-factor/backup-codes/index.mjs +12 -6
- package/dist/plugins/two-factor/client.d.mts +16 -19
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/constant.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +15 -18
- package/dist/plugins/two-factor/index.d.mts +31 -35
- package/dist/plugins/two-factor/index.mjs +6 -3
- package/dist/plugins/two-factor/otp/index.d.mts +5 -8
- package/dist/plugins/two-factor/otp/index.mjs +159 -154
- package/dist/plugins/two-factor/schema.d.mts +2 -3
- package/dist/plugins/two-factor/totp/index.d.mts +7 -10
- package/dist/plugins/two-factor/totp/index.mjs +153 -148
- package/dist/plugins/two-factor/types.d.mts +6 -7
- package/dist/plugins/username/client.d.mts +12 -14
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +11 -14
- package/dist/plugins/username/index.d.mts +26 -31
- package/dist/plugins/username/schema.d.mts +7 -10
- package/dist/state.d.mts +4 -5
- package/dist/test-utils/headers.d.mts +2 -3
- package/dist/test-utils/http-test-instance.d.mts +26 -29
- package/dist/test-utils/test-instance.d.mts +7 -6
- package/dist/test-utils/test-instance.mjs +4 -2
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +4 -6
- package/dist/types/auth.d.mts +2 -4
- package/dist/types/helper.d.mts +11 -12
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +4 -5
- package/dist/types/plugins.d.mts +7 -8
- package/dist/utils/hide-metadata.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/is-api-error.mjs +1 -2
- package/dist/utils/time.d.mts +4 -4
- package/dist/utils/url.d.mts +13 -15
- package/dist/utils/wildcard.mjs +5 -3
- package/package.json +12 -12
package/dist/api/index.mjs
CHANGED
|
@@ -110,41 +110,42 @@ function getEndpoints(ctx, options) {
|
|
|
110
110
|
middleware
|
|
111
111
|
};
|
|
112
112
|
})).filter((plugin) => plugin !== void 0).flat() || [];
|
|
113
|
+
const endpoints = {
|
|
114
|
+
signInSocial: signInSocial(),
|
|
115
|
+
callbackOAuth,
|
|
116
|
+
getSession: getSession(),
|
|
117
|
+
signOut,
|
|
118
|
+
signUpEmail: signUpEmail(),
|
|
119
|
+
signInEmail: signInEmail(),
|
|
120
|
+
resetPassword,
|
|
121
|
+
verifyPassword,
|
|
122
|
+
verifyEmail,
|
|
123
|
+
sendVerificationEmail,
|
|
124
|
+
changeEmail,
|
|
125
|
+
changePassword,
|
|
126
|
+
setPassword,
|
|
127
|
+
updateSession: updateSession(),
|
|
128
|
+
updateUser: updateUser(),
|
|
129
|
+
deleteUser,
|
|
130
|
+
requestPasswordReset,
|
|
131
|
+
requestPasswordResetCallback,
|
|
132
|
+
listSessions: listSessions(),
|
|
133
|
+
revokeSession,
|
|
134
|
+
revokeSessions,
|
|
135
|
+
revokeOtherSessions,
|
|
136
|
+
linkSocialAccount,
|
|
137
|
+
listUserAccounts,
|
|
138
|
+
deleteUserCallback,
|
|
139
|
+
unlinkAccount,
|
|
140
|
+
refreshToken,
|
|
141
|
+
getAccessToken,
|
|
142
|
+
accountInfo,
|
|
143
|
+
...pluginEndpoints,
|
|
144
|
+
ok,
|
|
145
|
+
error
|
|
146
|
+
};
|
|
113
147
|
return {
|
|
114
|
-
api: toAuthEndpoints(
|
|
115
|
-
signInSocial: signInSocial(),
|
|
116
|
-
callbackOAuth,
|
|
117
|
-
getSession: getSession(),
|
|
118
|
-
signOut,
|
|
119
|
-
signUpEmail: signUpEmail(),
|
|
120
|
-
signInEmail: signInEmail(),
|
|
121
|
-
resetPassword,
|
|
122
|
-
verifyPassword,
|
|
123
|
-
verifyEmail,
|
|
124
|
-
sendVerificationEmail,
|
|
125
|
-
changeEmail,
|
|
126
|
-
changePassword,
|
|
127
|
-
setPassword,
|
|
128
|
-
updateSession: updateSession(),
|
|
129
|
-
updateUser: updateUser(),
|
|
130
|
-
deleteUser,
|
|
131
|
-
requestPasswordReset,
|
|
132
|
-
requestPasswordResetCallback,
|
|
133
|
-
listSessions: listSessions(),
|
|
134
|
-
revokeSession,
|
|
135
|
-
revokeSessions,
|
|
136
|
-
revokeOtherSessions,
|
|
137
|
-
linkSocialAccount,
|
|
138
|
-
listUserAccounts,
|
|
139
|
-
deleteUserCallback,
|
|
140
|
-
unlinkAccount,
|
|
141
|
-
refreshToken,
|
|
142
|
-
getAccessToken,
|
|
143
|
-
accountInfo,
|
|
144
|
-
...pluginEndpoints,
|
|
145
|
-
ok,
|
|
146
|
-
error
|
|
147
|
-
}, ctx),
|
|
148
|
+
api: toAuthEndpoints(endpoints, ctx),
|
|
148
149
|
middlewares
|
|
149
150
|
};
|
|
150
151
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as _$better_call0 from "better-call";
|
|
2
|
-
|
|
3
1
|
//#region src/api/middlewares/authorization.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* Middleware that verifies the authenticated user owns a resource.
|
|
@@ -13,10 +11,14 @@ import * as _$better_call0 from "better-call";
|
|
|
13
11
|
* The fetched resource is returned on `ctx.context.verifiedResource`
|
|
14
12
|
* so the handler can use it without a redundant DB query.
|
|
15
13
|
*/
|
|
16
|
-
declare function requireResourceOwnership(config: {
|
|
17
|
-
/** Database model name (e.g., "passkey", "apiKey") */
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
export declare function requireResourceOwnership(config: {
|
|
15
|
+
/** Database model name (e.g., "passkey", "apiKey") */
|
|
16
|
+
model: string;
|
|
17
|
+
/** Request parameter name containing the resource ID */
|
|
18
|
+
idParam: string;
|
|
19
|
+
/** Where to find the ID: "body" or "query" */
|
|
20
|
+
idSource: "body" | "query";
|
|
21
|
+
/** Field on the resource that holds the owner's user ID. Default: "userId" */
|
|
20
22
|
ownerField?: string;
|
|
21
23
|
/**
|
|
22
24
|
* Custom error to throw when the resource is not found.
|
|
@@ -41,7 +43,7 @@ declare function requireResourceOwnership(config: {
|
|
|
41
43
|
* @default "FORBIDDEN" (403)
|
|
42
44
|
*/
|
|
43
45
|
forbiddenStatus?: "FORBIDDEN" | "UNAUTHORIZED";
|
|
44
|
-
}):
|
|
46
|
+
}): import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
45
47
|
verifiedResource: {};
|
|
46
48
|
}>>;
|
|
47
49
|
/**
|
|
@@ -54,16 +56,17 @@ declare function requireResourceOwnership(config: {
|
|
|
54
56
|
*
|
|
55
57
|
* The verified member is returned on `ctx.context.verifiedMember`.
|
|
56
58
|
*/
|
|
57
|
-
declare function requireOrgRole(config: {
|
|
58
|
-
/** Request parameter name containing the organization ID */
|
|
59
|
+
export declare function requireOrgRole(config: {
|
|
60
|
+
/** Request parameter name containing the organization ID */
|
|
61
|
+
orgIdParam: string;
|
|
62
|
+
/** Where to find the org ID: "body" or "query" */
|
|
59
63
|
orgIdSource: "body" | "query";
|
|
60
64
|
/**
|
|
61
65
|
* Roles that are authorized to proceed. If omitted or empty,
|
|
62
66
|
* any org membership is sufficient.
|
|
63
67
|
*/
|
|
64
68
|
allowedRoles?: string[];
|
|
65
|
-
}):
|
|
69
|
+
}): import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
66
70
|
verifiedMember: {};
|
|
67
71
|
}>>;
|
|
68
|
-
//#endregion
|
|
69
|
-
export { requireOrgRole, requireResourceOwnership };
|
|
72
|
+
//#endregion
|
|
@@ -69,7 +69,8 @@ function requireOrgRole(config) {
|
|
|
69
69
|
});
|
|
70
70
|
if (!member) throw new APIError("FORBIDDEN", { message: "Not a member of this organization" });
|
|
71
71
|
if (config.allowedRoles?.length) {
|
|
72
|
-
|
|
72
|
+
const rawRole = member.role ?? "";
|
|
73
|
+
if (!parseMemberRoles(rawRole).some((role) => config.allowedRoles.includes(role))) throw new APIError("FORBIDDEN", { message: "Insufficient role for this operation" });
|
|
73
74
|
}
|
|
74
75
|
return { verifiedMember: member };
|
|
75
76
|
});
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { requireOrgRole, requireResourceOwnership } from "./authorization.mjs";
|
|
2
|
-
import { formCsrfMiddleware, originCheck, originCheckMiddleware } from "./origin-check.mjs";
|
|
2
|
+
import { formCsrfMiddleware, originCheck, originCheckMiddleware } from "./origin-check.mjs";
|
|
3
|
+
export { formCsrfMiddleware, originCheck, originCheckMiddleware, requireOrgRole, requireResourceOwnership };
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
2
|
-
import * as _$better_call0 from "better-call";
|
|
3
|
-
|
|
4
2
|
//#region src/api/middlewares/origin-check.d.ts
|
|
5
3
|
/**
|
|
6
4
|
* A middleware to validate callbackURL and origin against trustedOrigins.
|
|
7
5
|
* Also handles CSRF protection using Fetch Metadata for first-login scenarios.
|
|
8
6
|
*/
|
|
9
|
-
declare const originCheckMiddleware:
|
|
10
|
-
declare const originCheck: (getValue: (ctx: GenericEndpointContext) => string | string[]) =>
|
|
7
|
+
export declare const originCheckMiddleware: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
8
|
+
export declare const originCheck: (getValue: (ctx: GenericEndpointContext) => string | string[]) => import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
11
9
|
/**
|
|
12
10
|
* Middleware for CSRF protection using Fetch Metadata headers.
|
|
13
11
|
* This prevents cross-site navigation login attacks while supporting progressive enhancement.
|
|
14
12
|
*/
|
|
15
|
-
declare const formCsrfMiddleware:
|
|
16
|
-
//#endregion
|
|
17
|
-
export { formCsrfMiddleware, originCheck, originCheckMiddleware };
|
|
13
|
+
export declare const formCsrfMiddleware: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
14
|
+
//#endregion
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import * as _$_better_auth_core_oauth20 from "@better-auth/core/oauth2";
|
|
2
|
-
import * as _$better_call0 from "better-call";
|
|
3
1
|
import * as z from "zod";
|
|
4
|
-
|
|
5
2
|
//#region src/api/routes/account.d.ts
|
|
6
|
-
declare const listUserAccounts:
|
|
3
|
+
export declare const listUserAccounts: import("better-call").StrictEndpoint<"/list-accounts", {
|
|
7
4
|
method: "GET";
|
|
8
|
-
use:
|
|
5
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
9
6
|
session: {
|
|
10
7
|
session: Record<string, any> & {
|
|
11
8
|
id: string;
|
|
@@ -87,7 +84,7 @@ declare const listUserAccounts: _$better_call0.StrictEndpoint<"/list-accounts",
|
|
|
87
84
|
providerId: string;
|
|
88
85
|
accountId: string;
|
|
89
86
|
}[]>;
|
|
90
|
-
declare const linkSocialAccount:
|
|
87
|
+
export declare const linkSocialAccount: import("better-call").StrictEndpoint<"/link-social", {
|
|
91
88
|
method: "POST";
|
|
92
89
|
requireHeaders: true;
|
|
93
90
|
body: z.ZodObject<{
|
|
@@ -107,7 +104,7 @@ declare const linkSocialAccount: _$better_call0.StrictEndpoint<"/link-social", {
|
|
|
107
104
|
additionalParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
108
105
|
additionalData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
109
106
|
}, z.core.$strip>;
|
|
110
|
-
use:
|
|
107
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
111
108
|
session: {
|
|
112
109
|
session: Record<string, any> & {
|
|
113
110
|
id: string;
|
|
@@ -166,12 +163,12 @@ declare const linkSocialAccount: _$better_call0.StrictEndpoint<"/link-social", {
|
|
|
166
163
|
url: string;
|
|
167
164
|
redirect: boolean;
|
|
168
165
|
}>;
|
|
169
|
-
declare const unlinkAccount:
|
|
166
|
+
export declare const unlinkAccount: import("better-call").StrictEndpoint<"/unlink-account", {
|
|
170
167
|
method: "POST";
|
|
171
168
|
body: z.ZodObject<{
|
|
172
169
|
accountId: z.ZodString;
|
|
173
170
|
}, z.core.$strip>;
|
|
174
|
-
use:
|
|
171
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
175
172
|
session: {
|
|
176
173
|
session: Record<string, any> & {
|
|
177
174
|
id: string;
|
|
@@ -219,7 +216,7 @@ declare const unlinkAccount: _$better_call0.StrictEndpoint<"/unlink-account", {
|
|
|
219
216
|
}, {
|
|
220
217
|
status: boolean;
|
|
221
218
|
}>;
|
|
222
|
-
declare const getAccessToken:
|
|
219
|
+
export declare const getAccessToken: import("better-call").StrictEndpoint<"/get-access-token", {
|
|
223
220
|
method: "POST";
|
|
224
221
|
body: z.ZodUnion<readonly [z.ZodObject<{
|
|
225
222
|
accountId: z.ZodString;
|
|
@@ -269,7 +266,7 @@ declare const getAccessToken: _$better_call0.StrictEndpoint<"/get-access-token",
|
|
|
269
266
|
scopes: string[];
|
|
270
267
|
idToken: string | undefined;
|
|
271
268
|
}>;
|
|
272
|
-
declare const refreshToken:
|
|
269
|
+
export declare const refreshToken: import("better-call").StrictEndpoint<"/refresh-token", {
|
|
273
270
|
method: "POST";
|
|
274
271
|
body: z.ZodUnion<readonly [z.ZodObject<{
|
|
275
272
|
accountId: z.ZodString;
|
|
@@ -330,7 +327,7 @@ declare const refreshToken: _$better_call0.StrictEndpoint<"/refresh-token", {
|
|
|
330
327
|
providerId: string;
|
|
331
328
|
accountId: string;
|
|
332
329
|
}>;
|
|
333
|
-
declare const accountInfo:
|
|
330
|
+
export declare const accountInfo: import("better-call").StrictEndpoint<"/account-info", {
|
|
334
331
|
method: "GET";
|
|
335
332
|
metadata: {
|
|
336
333
|
openapi: {
|
|
@@ -406,8 +403,7 @@ declare const accountInfo: _$better_call0.StrictEndpoint<"/account-info", {
|
|
|
406
403
|
providerId: string;
|
|
407
404
|
accountId: string;
|
|
408
405
|
};
|
|
409
|
-
user:
|
|
406
|
+
user: import("@better-auth/core/oauth2").OAuth2UserInfo;
|
|
410
407
|
data: object;
|
|
411
408
|
}>;
|
|
412
|
-
//#endregion
|
|
413
|
-
export { accountInfo, getAccessToken, linkSocialAccount, listUserAccounts, refreshToken, unlinkAccount };
|
|
409
|
+
//#endregion
|
|
@@ -506,10 +506,13 @@ const refreshToken = createAuthEndpoint("/refresh-token", {
|
|
|
506
506
|
* @see {@link Account.scope}
|
|
507
507
|
*/
|
|
508
508
|
updatedAccount = await ctx.context.internalAdapter.updateAccount(account.id, updatedTokenData);
|
|
509
|
-
if (accountCookie?.id === account.id && ctx.context.options.account?.storeAccountCookie)
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
509
|
+
if (accountCookie?.id === account.id && ctx.context.options.account?.storeAccountCookie) {
|
|
510
|
+
const updateData = {
|
|
511
|
+
...accountCookie,
|
|
512
|
+
...updatedAccount ?? updatedTokenData
|
|
513
|
+
};
|
|
514
|
+
await setAccountCookie(ctx, updateData);
|
|
515
|
+
}
|
|
513
516
|
const responseScope = updatedAccount?.scope ?? account.scope;
|
|
514
517
|
return ctx.json({
|
|
515
518
|
accessToken: tokens.accessToken,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import * as _$better_call0 from "better-call";
|
|
2
1
|
import * as z from "zod";
|
|
3
|
-
|
|
4
2
|
//#region src/api/routes/callback.d.ts
|
|
5
|
-
declare const callbackOAuth:
|
|
3
|
+
export declare const callbackOAuth: import("better-call").StrictEndpoint<"/callback/:id", {
|
|
6
4
|
method: ("GET" | "POST")[];
|
|
7
5
|
operationId: string;
|
|
8
6
|
body: z.ZodOptional<z.ZodObject<{
|
|
@@ -28,5 +26,4 @@ declare const callbackOAuth: _$better_call0.StrictEndpoint<"/callback/:id", {
|
|
|
28
26
|
scope: "server";
|
|
29
27
|
};
|
|
30
28
|
}, void>;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { callbackOAuth };
|
|
29
|
+
//#endregion
|
|
@@ -50,7 +50,8 @@ const callbackOAuth = createAuthEndpoint("/callback/:id", {
|
|
|
50
50
|
else throw new Error("Unsupported method");
|
|
51
51
|
} catch (e) {
|
|
52
52
|
c.context.logger.error("INVALID_CALLBACK_REQUEST", e);
|
|
53
|
-
const
|
|
53
|
+
const params = new URLSearchParams({ error: "invalid_callback_request" });
|
|
54
|
+
const redirectURL = appendQueryParams(defaultErrorURL, params);
|
|
54
55
|
throw c.redirect(redirectURL);
|
|
55
56
|
}
|
|
56
57
|
const { code, error, state, error_description, device_id, user: userData, iss } = queryOrBody;
|
|
@@ -70,7 +71,8 @@ const callbackOAuth = createAuthEndpoint("/callback/:id", {
|
|
|
70
71
|
}
|
|
71
72
|
if (!state) {
|
|
72
73
|
c.context.logger.error("State not found", error);
|
|
73
|
-
const
|
|
74
|
+
const params = new URLSearchParams({ error: "state_not_found" });
|
|
75
|
+
const redirectURL = appendQueryParams(defaultErrorURL, params);
|
|
74
76
|
throw c.redirect(redirectURL);
|
|
75
77
|
}
|
|
76
78
|
const { codeVerifier, callbackURL, link, errorURL, newUserURL, requestSignUp, idTokenNonce } = await parseState(c);
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { 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/api/routes/email-verification.d.ts
|
|
7
|
-
declare function createEmailVerificationToken(secret: string, email: string,
|
|
6
|
+
export declare function createEmailVerificationToken(secret: string, email: string,
|
|
8
7
|
/**
|
|
9
8
|
* The email to update from
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
10
|
updateTo?: string | undefined,
|
|
13
11
|
/**
|
|
14
12
|
* The time in seconds for the token to expire
|
|
15
13
|
*/
|
|
16
|
-
|
|
17
14
|
expiresIn?: number,
|
|
18
15
|
/**
|
|
19
16
|
* Extra payload to include in the token
|
|
20
17
|
*/
|
|
21
|
-
|
|
22
18
|
extraPayload?: Record<string, any>): Promise<string>;
|
|
23
19
|
/**
|
|
24
20
|
* A function to send a verification email to the user
|
|
25
21
|
*/
|
|
26
|
-
declare function sendVerificationEmailFn(ctx: GenericEndpointContext, user: User): Promise<void>;
|
|
27
|
-
declare const sendVerificationEmail:
|
|
22
|
+
export declare function sendVerificationEmailFn(ctx: GenericEndpointContext, user: User): Promise<void>;
|
|
23
|
+
export declare const sendVerificationEmail: import("better-call").StrictEndpoint<"/send-verification-email", {
|
|
28
24
|
method: "POST";
|
|
29
25
|
operationId: string;
|
|
30
26
|
cloneRequest: true;
|
|
@@ -100,14 +96,14 @@ declare const sendVerificationEmail: _$better_call0.StrictEndpoint<"/send-verifi
|
|
|
100
96
|
}, {
|
|
101
97
|
status: boolean;
|
|
102
98
|
}>;
|
|
103
|
-
declare const verifyEmail:
|
|
99
|
+
export declare const verifyEmail: import("better-call").StrictEndpoint<"/verify-email", {
|
|
104
100
|
method: "GET";
|
|
105
101
|
operationId: string;
|
|
106
102
|
query: z.ZodObject<{
|
|
107
103
|
token: z.ZodString;
|
|
108
104
|
callbackURL: z.ZodOptional<z.ZodString>;
|
|
109
105
|
}, z.core.$strip>;
|
|
110
|
-
use:
|
|
106
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
111
107
|
metadata: {
|
|
112
108
|
openapi: {
|
|
113
109
|
description: string;
|
|
@@ -156,5 +152,4 @@ declare const verifyEmail: _$better_call0.StrictEndpoint<"/verify-email", {
|
|
|
156
152
|
}, void | {
|
|
157
153
|
status: boolean;
|
|
158
154
|
}>;
|
|
159
|
-
//#endregion
|
|
160
|
-
export { createEmailVerificationToken, sendVerificationEmail, sendVerificationEmailFn, verifyEmail };
|
|
155
|
+
//#endregion
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as _$better_call0 from "better-call";
|
|
2
|
-
|
|
3
1
|
//#region src/api/routes/error.d.ts
|
|
4
|
-
declare const error:
|
|
2
|
+
export declare const error: import("better-call").StrictEndpoint<"/error", {
|
|
5
3
|
method: "GET";
|
|
6
4
|
metadata: {
|
|
7
5
|
openapi: {
|
|
@@ -23,5 +21,4 @@ declare const error: _$better_call0.StrictEndpoint<"/error", {
|
|
|
23
21
|
scope: "server";
|
|
24
22
|
};
|
|
25
23
|
}, Response>;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { error };
|
|
24
|
+
//#endregion
|
|
@@ -9,4 +9,5 @@ import { signInEmail, signInSocial } from "./sign-in.mjs";
|
|
|
9
9
|
import { signOut } from "./sign-out.mjs";
|
|
10
10
|
import { signUpEmail } from "./sign-up.mjs";
|
|
11
11
|
import { updateSession } from "./update-session.mjs";
|
|
12
|
-
import { changeEmail, changePassword, deleteUser, deleteUserCallback, setPassword, updateUser } from "./update-user.mjs";
|
|
12
|
+
import { changeEmail, changePassword, deleteUser, deleteUserCallback, setPassword, updateUser } from "./update-user.mjs";
|
|
13
|
+
export { accountInfo, callbackOAuth, changeEmail, changePassword, createEmailVerificationToken, deleteUser, deleteUserCallback, error, freshSessionMiddleware, getAccessToken, getAuthoritativeSessionFromCtx, getSession, getSessionFromCtx, isStateful, linkSocialAccount, listSessions, listUserAccounts, ok, refreshToken, requestOnlySessionMiddleware, requestPasswordReset, requestPasswordResetCallback, resetPassword, revokeOtherSessions, revokeSession, revokeSessions, sendVerificationEmail, sendVerificationEmailFn, sensitiveSessionMiddleware, sessionMiddleware, setPassword, signInEmail, signInSocial, signOut, signUpEmail, unlinkAccount, updateSession, updateUser, verifyEmail, verifyPassword };
|
package/dist/api/routes/ok.d.mts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as _$better_call0 from "better-call";
|
|
2
|
-
|
|
3
1
|
//#region src/api/routes/ok.d.ts
|
|
4
|
-
declare const ok:
|
|
2
|
+
export declare const ok: import("better-call").StrictEndpoint<"/ok", {
|
|
5
3
|
method: "GET";
|
|
6
4
|
metadata: {
|
|
7
5
|
openapi: {
|
|
@@ -31,5 +29,4 @@ declare const ok: _$better_call0.StrictEndpoint<"/ok", {
|
|
|
31
29
|
}, {
|
|
32
30
|
ok: boolean;
|
|
33
31
|
}>;
|
|
34
|
-
//#endregion
|
|
35
|
-
export { ok };
|
|
32
|
+
//#endregion
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import * as _$better_call0 from "better-call";
|
|
2
1
|
import * as z from "zod";
|
|
3
|
-
|
|
4
2
|
//#region src/api/routes/password.d.ts
|
|
5
|
-
declare const requestPasswordReset:
|
|
3
|
+
export declare const requestPasswordReset: import("better-call").StrictEndpoint<"/request-password-reset", {
|
|
6
4
|
method: "POST";
|
|
7
5
|
body: z.ZodObject<{
|
|
8
6
|
email: z.ZodEmail;
|
|
@@ -34,18 +32,18 @@ declare const requestPasswordReset: _$better_call0.StrictEndpoint<"/request-pass
|
|
|
34
32
|
};
|
|
35
33
|
};
|
|
36
34
|
};
|
|
37
|
-
use:
|
|
35
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
38
36
|
}, {
|
|
39
37
|
status: boolean;
|
|
40
38
|
message: string;
|
|
41
39
|
}>;
|
|
42
|
-
declare const requestPasswordResetCallback:
|
|
40
|
+
export declare const requestPasswordResetCallback: import("better-call").StrictEndpoint<"/reset-password/:token", {
|
|
43
41
|
method: "GET";
|
|
44
42
|
operationId: string;
|
|
45
43
|
query: z.ZodObject<{
|
|
46
44
|
callbackURL: z.ZodString;
|
|
47
45
|
}, z.core.$strip>;
|
|
48
|
-
use:
|
|
46
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
49
47
|
metadata: {
|
|
50
48
|
openapi: {
|
|
51
49
|
operationId: string;
|
|
@@ -87,7 +85,7 @@ declare const requestPasswordResetCallback: _$better_call0.StrictEndpoint<"/rese
|
|
|
87
85
|
};
|
|
88
86
|
};
|
|
89
87
|
}, never>;
|
|
90
|
-
declare const resetPassword:
|
|
88
|
+
export declare const resetPassword: import("better-call").StrictEndpoint<"/reset-password", {
|
|
91
89
|
method: "POST";
|
|
92
90
|
operationId: string;
|
|
93
91
|
query: z.ZodOptional<z.ZodObject<{
|
|
@@ -123,7 +121,7 @@ declare const resetPassword: _$better_call0.StrictEndpoint<"/reset-password", {
|
|
|
123
121
|
}, {
|
|
124
122
|
status: boolean;
|
|
125
123
|
}>;
|
|
126
|
-
declare const verifyPassword:
|
|
124
|
+
export declare const verifyPassword: import("better-call").StrictEndpoint<"/verify-password", {
|
|
127
125
|
method: "POST";
|
|
128
126
|
body: z.ZodObject<{
|
|
129
127
|
password: z.ZodString;
|
|
@@ -152,7 +150,7 @@ declare const verifyPassword: _$better_call0.StrictEndpoint<"/verify-password",
|
|
|
152
150
|
};
|
|
153
151
|
};
|
|
154
152
|
};
|
|
155
|
-
use:
|
|
153
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
156
154
|
session: {
|
|
157
155
|
session: Record<string, any> & {
|
|
158
156
|
id: string;
|
|
@@ -178,5 +176,4 @@ declare const verifyPassword: _$better_call0.StrictEndpoint<"/verify-password",
|
|
|
178
176
|
}, {
|
|
179
177
|
status: boolean;
|
|
180
178
|
}>;
|
|
181
|
-
//#endregion
|
|
182
|
-
export { requestPasswordReset, requestPasswordResetCallback, resetPassword, verifyPassword };
|
|
179
|
+
//#endregion
|
|
@@ -70,7 +70,7 @@ const requestPasswordReset = createAuthEndpoint("/request-password-reset", {
|
|
|
70
70
|
message: "If this email exists in our system, check your email for the reset link"
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
const expiresAt = getDate(ctx.context.options.emailAndPassword.resetPasswordTokenExpiresIn || 3600
|
|
73
|
+
const expiresAt = getDate(ctx.context.options.emailAndPassword.resetPasswordTokenExpiresIn || 3600, "sec");
|
|
74
74
|
const verificationToken = generateId(24);
|
|
75
75
|
await ctx.context.internalAdapter.createVerificationValue({
|
|
76
76
|
value: user.user.id,
|
|
@@ -157,7 +157,8 @@ const resetPassword = createAuthEndpoint("/reset-password", {
|
|
|
157
157
|
const userId = verification.value;
|
|
158
158
|
const user = await ctx.context.internalAdapter.findUserById(userId);
|
|
159
159
|
if (!user) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.USER_NOT_FOUND);
|
|
160
|
-
|
|
160
|
+
const hashedPassword = await ctx.context.password.hash(newPassword);
|
|
161
|
+
await resetCredentialPassword(ctx, userId, hashedPassword, async () => {
|
|
161
162
|
if (!await ctx.context.internalAdapter.consumeVerificationValue(id)) throw APIError.from("BAD_REQUEST", BASE_ERROR_CODES.INVALID_TOKEN);
|
|
162
163
|
});
|
|
163
164
|
if (ctx.context.options.emailAndPassword?.onPasswordReset) await ctx.context.options.emailAndPassword.onPasswordReset({ user }, ctx.request);
|