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
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Awaitable } from "@better-auth/core";
|
|
2
2
|
import { OAuth2Tokens, OAuth2UserInfo, OAuthAccountKeyContext, OAuthMappedUser, OAuthRefreshContext, TokenEndpointAuth } from "@better-auth/core/oauth2";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/generic-oauth/types.d.ts
|
|
5
4
|
/** Raw profile returned by a Generic OAuth provider. */
|
|
6
|
-
type GenericOAuthUserInfo = Omit<OAuth2UserInfo, "id"> & {
|
|
5
|
+
export type GenericOAuthUserInfo = Omit<OAuth2UserInfo, "id"> & {
|
|
7
6
|
id?: string | number | null | undefined;
|
|
8
7
|
sub?: string | number | null | undefined;
|
|
9
8
|
[key: string]: unknown;
|
|
10
9
|
};
|
|
11
|
-
interface GenericOAuthOptions<ID extends string = string> {
|
|
10
|
+
export interface GenericOAuthOptions<ID extends string = string> {
|
|
12
11
|
/**
|
|
13
12
|
* Array of OAuth provider configurations.
|
|
14
13
|
*/
|
|
@@ -17,7 +16,7 @@ interface GenericOAuthOptions<ID extends string = string> {
|
|
|
17
16
|
/**
|
|
18
17
|
* Configuration interface for generic OAuth providers.
|
|
19
18
|
*/
|
|
20
|
-
interface GenericOAuthConfig<ID extends string = string> {
|
|
19
|
+
export interface GenericOAuthConfig<ID extends string = string> {
|
|
21
20
|
/** Unique identifier for the OAuth provider */
|
|
22
21
|
providerId: ID;
|
|
23
22
|
/**
|
|
@@ -112,7 +111,8 @@ interface GenericOAuthConfig<ID extends string = string> {
|
|
|
112
111
|
responseType?: string | undefined;
|
|
113
112
|
/**
|
|
114
113
|
* The response mode to use for the authorization code request.
|
|
115
|
-
|
|
114
|
+
|
|
115
|
+
*/
|
|
116
116
|
responseMode?: ("query" | "form_post") | undefined;
|
|
117
117
|
/**
|
|
118
118
|
* Prompt parameter for the authorization request.
|
|
@@ -264,5 +264,4 @@ interface GenericOAuthConfig<ID extends string = string> {
|
|
|
264
264
|
*/
|
|
265
265
|
disableIdTokenNonceBinding?: boolean | undefined;
|
|
266
266
|
}
|
|
267
|
-
//#endregion
|
|
268
|
-
export { GenericOAuthConfig, GenericOAuthOptions, GenericOAuthUserInfo };
|
|
267
|
+
//#endregion
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
2
|
-
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
3
|
-
|
|
4
1
|
//#region src/plugins/haveibeenpwned/index.d.ts
|
|
5
2
|
declare module "@better-auth/core" {
|
|
6
3
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -16,8 +13,8 @@ declare module "@better-auth/core" {
|
|
|
16
13
|
* @returns Whether the password has been compromised.
|
|
17
14
|
* @throws {APIError} When the password could not be checked.
|
|
18
15
|
*/
|
|
19
|
-
declare function isPasswordCompromised(password: string): Promise<boolean>;
|
|
20
|
-
interface HaveIBeenPwnedOptions {
|
|
16
|
+
export declare function isPasswordCompromised(password: string): Promise<boolean>;
|
|
17
|
+
export interface HaveIBeenPwnedOptions {
|
|
21
18
|
/**
|
|
22
19
|
* Custom error message shown when a compromised password is detected.
|
|
23
20
|
*/
|
|
@@ -35,10 +32,10 @@ interface HaveIBeenPwnedOptions {
|
|
|
35
32
|
*/
|
|
36
33
|
enabled?: boolean | undefined;
|
|
37
34
|
}
|
|
38
|
-
declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
35
|
+
export declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
39
36
|
id: "have-i-been-pwned";
|
|
40
37
|
version: string;
|
|
41
|
-
init(ctx:
|
|
38
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
42
39
|
context: {
|
|
43
40
|
password: {
|
|
44
41
|
hash(password: string): Promise<string>;
|
|
@@ -50,14 +47,13 @@ declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
|
50
47
|
minPasswordLength: number;
|
|
51
48
|
maxPasswordLength: number;
|
|
52
49
|
};
|
|
53
|
-
checkPassword: (userId: string, ctx:
|
|
50
|
+
checkPassword: (userId: string, ctx: import("@better-auth/core").GenericEndpointContext<import("@better-auth/core").BetterAuthOptions>) => Promise<boolean>;
|
|
54
51
|
};
|
|
55
52
|
};
|
|
56
53
|
};
|
|
57
54
|
options: HaveIBeenPwnedOptions | undefined;
|
|
58
55
|
$ERROR_CODES: {
|
|
59
|
-
PASSWORD_COMPROMISED:
|
|
56
|
+
PASSWORD_COMPROMISED: import("@better-auth/core/utils/error-codes").RawError<"PASSWORD_COMPROMISED">;
|
|
60
57
|
};
|
|
61
58
|
};
|
|
62
|
-
//#endregion
|
|
63
|
-
export { HaveIBeenPwnedOptions, haveIBeenPwned, isPasswordCompromised };
|
|
59
|
+
//#endregion
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -2,11 +2,13 @@ import { InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPlug
|
|
|
2
2
|
import { HIDE_METADATA } from "../utils/hide-metadata.mjs";
|
|
3
3
|
import { AccessControl, ArrayElement, ExactRoleStatements, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, Statements, SubArray, Subset } from "./access/types.mjs";
|
|
4
4
|
import { AuthorizeResponse, createAccessControl, role } from "./access/access.mjs";
|
|
5
|
+
import "./access/index.mjs";
|
|
5
6
|
import { OrganizationOptions } from "./organization/types.mjs";
|
|
6
7
|
import { InferInvitation, InferMember, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferTeam, Invitation, InvitationInput, InvitationStatus, Member, MemberInput, Organization, OrganizationInput, OrganizationRole, OrganizationSchema, Team, TeamInput, TeamMember, TeamMemberInput, defaultRolesSchema, invitationSchema, invitationStatus, memberSchema, organizationRoleSchema, organizationSchema, roleSchema, teamMemberSchema, teamSchema } from "./organization/schema.mjs";
|
|
7
8
|
import { getOrgAdapter } from "./organization/adapter.mjs";
|
|
8
9
|
import { AdminOptions, InferAdminRolesFromOption, SessionWithImpersonatedBy, UserWithRole } from "./admin/types.mjs";
|
|
9
10
|
import { admin } from "./admin/admin.mjs";
|
|
11
|
+
import "./admin/index.mjs";
|
|
10
12
|
import { AnonymousOptions, AnonymousSession, UserWithAnonymous } from "./anonymous/types.mjs";
|
|
11
13
|
import { anonymous } from "./anonymous/index.mjs";
|
|
12
14
|
import { BearerOptions, bearer } from "./bearer/index.mjs";
|
|
@@ -66,4 +68,5 @@ import { USERNAME_ERROR_CODES } from "./username/error-codes.mjs";
|
|
|
66
68
|
import { UsernameOptions, UsernamePlugin, UsernamePluginWithoutDisplayUsername, username } from "./username/index.mjs";
|
|
67
69
|
import { hasPermission } from "./organization/has-permission.mjs";
|
|
68
70
|
import { DefaultOrganizationPlugin, DynamicAccessControlEndpoints, OrganizationCreator, OrganizationEndpoints, OrganizationPlugin, TeamEndpoints, organization, parseRoles } from "./organization/organization.mjs";
|
|
69
|
-
|
|
71
|
+
import "./organization/index.mjs";
|
|
72
|
+
export { AccessControl, type AdminOptions, type AnonymousOptions, type AnonymousSession, ArrayElement, type Auth0Options, AuthorizeResponse, type BackupCodeOptions, type BaseCaptchaOptions, BaseOAuthProviderOptions, BearerOptions, type BotIdVerification, type CaptchaFoxOptions, type CaptchaOptions, type CloudflareTurnstileOptions, CustomSessionPluginOptions, DefaultOrganizationPlugin, DeviceAuthorizationGrant, DeviceAuthorizationGrantAuthorization, DeviceAuthorizationOptions, DeviceAuthorizationPluginOptions, DeviceAuthorizationRequest, type DeviceCode, type DeviceCodeRedemptionAuthorization, type DeviceCodeRedemptionResult, DynamicAccessControlEndpoints, MULTI_SESSION_ERROR_CODES as ERROR_CODES, type EmailOTPOptions, ExactRoleStatements, type FieldSchema, type GenericOAuthConfig, type GenericOAuthOptions, type GenericOAuthUserInfo, type GoogleRecaptchaOptions, type GumroadOptions, type HCaptchaOptions, HIDE_METADATA, HaveIBeenPwnedOptions, type HubSpotOptions, type InferAdminRolesFromOption, type InferInvitation, type InferMember, InferOptionSchema, type InferOrganization, type InferOrganizationRolesFromOption, type InferOrganizationZodRolesFromOption, InferPluginContext, InferPluginErrorCodes, InferPluginIDs, type InferTeam, type Invitation, type InvitationInput, type InvitationStatus, type JWKOptions, type JWSAlgorithms, type Jwk, type JwtOptions, type KeycloakOptions, LastLoginMethodOptions, type LineOptions, type LoginResult, MagicLinkOptions, type Member, type MemberInput, type MicrosoftEntraIdOptions, MultiSessionConfig, OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_DATA_ELEMENT_ID, OAUTH_POPUP_ERROR_CODES, OAUTH_POPUP_MESSAGE_TYPE, OAUTH_POPUP_SCRIPT_CSP_HASH, type OAuthPopupData, type OAuthPopupMessage, OAuthProxyOptions, type OTPOptions, type OktaOptions, OneTapOptions, OneTimeTokenOptions, type OpenAPIModelSchema, OpenAPIOptions, type OpenAPIParameter, type OpenAPISchema, type Organization, OrganizationCreator, OrganizationEndpoints, type OrganizationInput, type OrganizationOptions, OrganizationPlugin, type OrganizationRole, type OrganizationSchema, POPUP_MARKER_COOKIE, type Path, type PatreonOptions, type PhoneNumberOptions, type Provider, type ResolvedSigningKey, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, SIWEPluginOptions, type SessionWithImpersonatedBy, type SlackOptions, Statements, SubArray, Subset, type TOTPOptions, TWO_FACTOR_ERROR_CODES, type Team, TeamEndpoints, type TeamInput, type TeamMember, type TeamMemberInput, type TestAuthOptions, type TestCookie, type TestHelpers, type TestUtilsOptions, type TimeString, TwoFactorOptions, TwoFactorProvider, TwoFactorTable, USERNAME_ERROR_CODES, type UserWithAnonymous, type UserWithPhoneNumber, type UserWithRole, UserWithTwoFactor, UsernameOptions, UsernamePlugin, UsernamePluginWithoutDisplayUsername, type ValidateRequestContext, type VercelBotIdOptions, type YandexOptions, admin, anonymous, auth0, type backupCode2fa, bearer, captcha, createAccessControl, createJwk, customSession, type defaultRolesSchema, deviceAuthorization, deviceAuthorizationOptionsSchema, emailOTP, type encodeBackupCodes, type generateBackupCodes, generateExportedKeyPair, type generator, genericOAuth, type getBackupCodes, getJwtToken, getOrgAdapter, gumroad, hasPermission, haveIBeenPwned, hubspot, type invitationSchema, type invitationStatus, isPasswordCompromised, jwt, keycloak, lastLoginMethod, line, magicLink, type memberSchema, microsoftEntraId, type ms, multiSession, oAuthProxy, oauthPopup, okta, oneTap, oneTimeToken, openAPI, organization, type organizationRoleSchema, type organizationSchema, type otp2fa, parseRoles, patreon, phoneNumber, redeemDeviceCode, resolveSigningKey, role, type roleSchema, type sec, signJWT, siwe, slack, type teamMemberSchema, type teamSchema, testUtils, toExpJWT, type totp2fa, twoFactor, twoFactorClient, username, type verifyBackupCode, verifyJWT, yandex };
|
|
@@ -3,7 +3,6 @@ import { jwt } from "./index.mjs";
|
|
|
3
3
|
import { BetterAuthClientOptions, ClientFetchOption, ClientStore } from "@better-auth/core";
|
|
4
4
|
import { JSONWebKeySet } from "jose";
|
|
5
5
|
import { BetterFetch } from "@better-fetch/fetch";
|
|
6
|
-
|
|
7
6
|
//#region src/plugins/jwt/client.d.ts
|
|
8
7
|
interface JwtClientOptions {
|
|
9
8
|
jwks?: {
|
|
@@ -16,7 +15,7 @@ interface JwtClientOptions {
|
|
|
16
15
|
jwksPath?: string;
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
|
-
declare const jwtClient: (options?: JwtClientOptions) => {
|
|
18
|
+
export declare const jwtClient: (options?: JwtClientOptions) => {
|
|
20
19
|
id: "better-auth-client";
|
|
21
20
|
version: string;
|
|
22
21
|
$InferServerPlugin: ReturnType<typeof jwt>;
|
|
@@ -38,4 +37,4 @@ declare const jwtClient: (options?: JwtClientOptions) => {
|
|
|
38
37
|
};
|
|
39
38
|
};
|
|
40
39
|
//#endregion
|
|
41
|
-
export {
|
|
40
|
+
export type { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey };
|
|
@@ -2,11 +2,8 @@ import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey } from "
|
|
|
2
2
|
import { getJwtToken, resolveSigningKey, signJWT } from "./sign.mjs";
|
|
3
3
|
import { createJwk, generateExportedKeyPair, toExpJWT } from "./utils.mjs";
|
|
4
4
|
import { verifyJWT } from "./verify.mjs";
|
|
5
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
6
|
-
import * as _$better_call0 from "better-call";
|
|
7
5
|
import * as z from "zod";
|
|
8
6
|
import { JSONWebKeySet, JWTPayload } from "jose";
|
|
9
|
-
|
|
10
7
|
//#region src/plugins/jwt/index.d.ts
|
|
11
8
|
declare module "@better-auth/core" {
|
|
12
9
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -15,14 +12,14 @@ declare module "@better-auth/core" {
|
|
|
15
12
|
};
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
15
|
+
export declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
19
16
|
id: "jwt";
|
|
20
17
|
version: string;
|
|
21
18
|
options: NoInfer<O>;
|
|
22
|
-
init(ctx:
|
|
19
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
23
20
|
context: {
|
|
24
21
|
sessionConfig: {
|
|
25
|
-
cookieCacheSigner:
|
|
22
|
+
cookieCacheSigner: import("@better-auth/core").CookieCacheSigner;
|
|
26
23
|
updateAge: number;
|
|
27
24
|
expiresIn: number;
|
|
28
25
|
freshAge: number;
|
|
@@ -34,7 +31,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
34
31
|
};
|
|
35
32
|
} | undefined;
|
|
36
33
|
endpoints: {
|
|
37
|
-
getJwks:
|
|
34
|
+
getJwks: import("better-call").StrictEndpoint<string, {
|
|
38
35
|
method: "GET";
|
|
39
36
|
metadata: {
|
|
40
37
|
openapi: {
|
|
@@ -111,10 +108,10 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
111
108
|
};
|
|
112
109
|
};
|
|
113
110
|
}, JSONWebKeySet>;
|
|
114
|
-
getToken:
|
|
111
|
+
getToken: import("better-call").StrictEndpoint<"/token", {
|
|
115
112
|
method: "GET";
|
|
116
113
|
requireHeaders: true;
|
|
117
|
-
use:
|
|
114
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
118
115
|
session: {
|
|
119
116
|
session: Record<string, any> & {
|
|
120
117
|
id: string;
|
|
@@ -163,7 +160,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
163
160
|
}, {
|
|
164
161
|
token: string;
|
|
165
162
|
}>;
|
|
166
|
-
signJWT:
|
|
163
|
+
signJWT: import("better-call").StrictEndpoint<string, {
|
|
167
164
|
method: "POST";
|
|
168
165
|
metadata: {
|
|
169
166
|
$Infer: {
|
|
@@ -180,7 +177,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
180
177
|
}, {
|
|
181
178
|
token: string;
|
|
182
179
|
}>;
|
|
183
|
-
verifyJWT:
|
|
180
|
+
verifyJWT: import("better-call").StrictEndpoint<string, {
|
|
184
181
|
method: "POST";
|
|
185
182
|
metadata: {
|
|
186
183
|
$Infer: {
|
|
@@ -207,8 +204,8 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
207
204
|
};
|
|
208
205
|
hooks: {
|
|
209
206
|
after: {
|
|
210
|
-
matcher(context:
|
|
211
|
-
handler:
|
|
207
|
+
matcher(context: import("@better-auth/core").HookEndpointContext): boolean;
|
|
208
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
212
209
|
}[];
|
|
213
210
|
};
|
|
214
211
|
schema: {
|
|
@@ -243,4 +240,4 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
243
240
|
};
|
|
244
241
|
};
|
|
245
242
|
//#endregion
|
|
246
|
-
export { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey, createJwk, generateExportedKeyPair, getJwtToken,
|
|
243
|
+
export { type JWKOptions, type JWSAlgorithms, type Jwk, type JwtOptions, type ResolvedSigningKey, createJwk, generateExportedKeyPair, getJwtToken, resolveSigningKey, signJWT, toExpJWT, verifyJWT };
|
|
@@ -122,7 +122,7 @@ const jwt = (options) => {
|
|
|
122
122
|
}
|
|
123
123
|
if (!keySets?.length) throw new BetterAuthError("No key sets found. Make sure you have a key in your database.");
|
|
124
124
|
const now = Date.now();
|
|
125
|
-
const gracePeriod = (options?.jwks?.gracePeriod ??
|
|
125
|
+
const gracePeriod = (options?.jwks?.gracePeriod ?? 2592e3) * 1e3;
|
|
126
126
|
const keys = keySets.filter((key) => {
|
|
127
127
|
if (!key.expiresAt) return true;
|
|
128
128
|
return key.expiresAt.getTime() + gracePeriod > now;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { JWSAlgorithms, JwtOptions, ResolvedSigningKey } from "./types.mjs";
|
|
2
2
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/jwt/sign.d.ts
|
|
5
4
|
type JWTPayloadWithOptional = {
|
|
6
5
|
/**
|
|
@@ -44,7 +43,8 @@ type JWTPayloadWithOptional = {
|
|
|
44
43
|
*
|
|
45
44
|
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
|
|
46
45
|
*/
|
|
47
|
-
iat?: number | undefined;
|
|
46
|
+
iat?: number | undefined;
|
|
47
|
+
/** Any other JWT Claim Set member. */
|
|
48
48
|
[propName: string]: unknown | undefined;
|
|
49
49
|
};
|
|
50
50
|
/**
|
|
@@ -65,7 +65,7 @@ type JWTPayloadWithOptional = {
|
|
|
65
65
|
* Used by the OAuth provider plugin to honor per-resource `signingAlgorithm` /
|
|
66
66
|
* `signingKeyId` overrides without re-implementing key resolution.
|
|
67
67
|
*/
|
|
68
|
-
interface SigningKeyOverrides {
|
|
68
|
+
export interface SigningKeyOverrides {
|
|
69
69
|
signingKeyId?: string | undefined;
|
|
70
70
|
signingAlgorithm?: JWSAlgorithms | undefined;
|
|
71
71
|
}
|
|
@@ -86,10 +86,11 @@ interface SigningKeyOverrides {
|
|
|
86
86
|
* tokens stay on the configured default algorithm even after extra algorithms
|
|
87
87
|
* have been lazy-minted for audience pinning.
|
|
88
88
|
*/
|
|
89
|
-
declare function resolveSigningKey(ctx: GenericEndpointContext, options?: JwtOptions, overrides?: SigningKeyOverrides): Promise<ResolvedSigningKey | null>;
|
|
90
|
-
declare function signJWT(ctx: GenericEndpointContext, config: {
|
|
89
|
+
export declare function resolveSigningKey(ctx: GenericEndpointContext, options?: JwtOptions, overrides?: SigningKeyOverrides): Promise<ResolvedSigningKey | null>;
|
|
90
|
+
export declare function signJWT(ctx: GenericEndpointContext, config: {
|
|
91
91
|
options?: JwtOptions | undefined;
|
|
92
|
-
payload: JWTPayloadWithOptional;
|
|
92
|
+
payload: JWTPayloadWithOptional;
|
|
93
|
+
/** Pre-resolved key from resolveSigningKey. Skips redundant DB lookup. */
|
|
93
94
|
resolvedKey?: ResolvedSigningKey;
|
|
94
95
|
/**
|
|
95
96
|
* Extra JWS Protected Header parameters to merge with the defaults
|
|
@@ -123,6 +124,6 @@ declare function signJWT(ctx: GenericEndpointContext, config: {
|
|
|
123
124
|
*/
|
|
124
125
|
signingAlgorithm?: JWSAlgorithms | undefined;
|
|
125
126
|
}): Promise<string>;
|
|
126
|
-
declare function getJwtToken(ctx: GenericEndpointContext, options?: JwtOptions | undefined): Promise<string>;
|
|
127
|
+
export declare function getJwtToken(ctx: GenericEndpointContext, options?: JwtOptions | undefined): Promise<string>;
|
|
127
128
|
//#endregion
|
|
128
|
-
export {
|
|
129
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Session, User } from "../../types/models.mjs";
|
|
2
2
|
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
3
|
+
import "../../types/index.mjs";
|
|
3
4
|
import { schema } from "./schema.mjs";
|
|
4
5
|
import { Awaitable, GenericEndpointContext } from "@better-auth/core";
|
|
5
6
|
import { JWTPayload } from "jose";
|
|
6
|
-
|
|
7
7
|
//#region src/plugins/jwt/types.d.ts
|
|
8
|
-
interface JwtOptions {
|
|
8
|
+
export interface JwtOptions {
|
|
9
9
|
/**
|
|
10
10
|
* Use the JWT plugin's locally managed signing keys for JWT session cookie
|
|
11
11
|
* cache values.
|
|
@@ -214,7 +214,7 @@ interface JwtOptions {
|
|
|
214
214
|
*
|
|
215
215
|
* @see https://github.com/panva/jose/issues/210
|
|
216
216
|
*/
|
|
217
|
-
type JWKOptions = {
|
|
217
|
+
export type JWKOptions = {
|
|
218
218
|
alg: "EdDSA";
|
|
219
219
|
crv?: "Ed25519" | undefined;
|
|
220
220
|
} | {
|
|
@@ -230,8 +230,8 @@ type JWKOptions = {
|
|
|
230
230
|
alg: "RS256";
|
|
231
231
|
modulusLength?: number | undefined;
|
|
232
232
|
};
|
|
233
|
-
type JWSAlgorithms = JWKOptions["alg"];
|
|
234
|
-
interface Jwk {
|
|
233
|
+
export type JWSAlgorithms = JWKOptions["alg"];
|
|
234
|
+
export interface Jwk {
|
|
235
235
|
id: string;
|
|
236
236
|
publicKey: string;
|
|
237
237
|
privateKey: string;
|
|
@@ -247,10 +247,9 @@ interface Jwk {
|
|
|
247
247
|
* read the `alg` before constructing the JWT payload
|
|
248
248
|
* (required for OIDC hash claims like at_hash).
|
|
249
249
|
*/
|
|
250
|
-
interface ResolvedSigningKey {
|
|
250
|
+
export interface ResolvedSigningKey {
|
|
251
251
|
alg: string;
|
|
252
252
|
kid: string;
|
|
253
253
|
privateKey: CryptoKey | Uint8Array;
|
|
254
254
|
}
|
|
255
|
-
//#endregion
|
|
256
|
-
export { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey };
|
|
255
|
+
//#endregion
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Jwk, JwtOptions } from "./types.mjs";
|
|
2
2
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as _$jose from "jose";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/jwt/utils.d.ts
|
|
6
4
|
/**
|
|
7
5
|
* Converts an expirationTime to ISO seconds expiration time (the format of JWT exp)
|
|
@@ -12,10 +10,10 @@ import * as _$jose from "jose";
|
|
|
12
10
|
* @param iat - the iat time to consolidate on
|
|
13
11
|
* @returns
|
|
14
12
|
*/
|
|
15
|
-
declare function toExpJWT(expirationTime: number | Date | string, iat: number): number;
|
|
16
|
-
declare function generateExportedKeyPair(options?: JwtOptions | undefined): Promise<{
|
|
17
|
-
publicWebKey:
|
|
18
|
-
privateWebKey:
|
|
13
|
+
export declare function toExpJWT(expirationTime: number | Date | string, iat: number): number;
|
|
14
|
+
export declare function generateExportedKeyPair(options?: JwtOptions | undefined): Promise<{
|
|
15
|
+
publicWebKey: import("jose").JWK;
|
|
16
|
+
privateWebKey: import("jose").JWK;
|
|
19
17
|
alg: "EdDSA" | "ES256" | "ES512" | "PS256" | "RS256";
|
|
20
18
|
cfg: {
|
|
21
19
|
crv?: "Ed25519" | undefined;
|
|
@@ -36,6 +34,5 @@ declare function generateExportedKeyPair(options?: JwtOptions | undefined): Prom
|
|
|
36
34
|
* @param options
|
|
37
35
|
* @returns
|
|
38
36
|
*/
|
|
39
|
-
declare function createJwk(ctx: GenericEndpointContext, options?: JwtOptions | undefined): Promise<Jwk>;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { createJwk, generateExportedKeyPair, toExpJWT };
|
|
37
|
+
export declare function createJwk(ctx: GenericEndpointContext, options?: JwtOptions | undefined): Promise<Jwk>;
|
|
38
|
+
//#endregion
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { JwtOptions } from "./types.mjs";
|
|
2
2
|
import { JWTPayload } from "jose";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/jwt/verify.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Verify a JWT token using the JWKS public keys
|
|
7
6
|
* Returns the payload if valid, null otherwise
|
|
8
7
|
*/
|
|
9
|
-
declare function verifyJWT<T extends JWTPayload = JWTPayload>(token: string, options?: JwtOptions): Promise<(T & Required<Pick<JWTPayload, "sub" | "aud">>) | null>;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { verifyJWT };
|
|
8
|
+
export declare function verifyJWT<T extends JWTPayload = JWTPayload>(token: string, options?: JwtOptions): Promise<(T & Required<Pick<JWTPayload, "sub" | "aud">>) | null>;
|
|
9
|
+
//#endregion
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for the client-side last login method plugin
|
|
4
4
|
*/
|
|
5
|
-
interface LastLoginMethodClientConfig {
|
|
5
|
+
export interface LastLoginMethodClientConfig {
|
|
6
6
|
/**
|
|
7
7
|
* Name of the cookie to read the last login method from
|
|
8
8
|
* @default "better-auth.last_used_login_method"
|
|
@@ -22,7 +22,7 @@ interface LastLoginMethodClientConfig {
|
|
|
22
22
|
/**
|
|
23
23
|
* Client-side plugin to retrieve the last used login method
|
|
24
24
|
*/
|
|
25
|
-
declare const lastLoginMethodClient: (config?: LastLoginMethodClientConfig) => {
|
|
25
|
+
export declare const lastLoginMethodClient: (config?: LastLoginMethodClientConfig) => {
|
|
26
26
|
id: "last-login-method-client";
|
|
27
27
|
version: string;
|
|
28
28
|
getActions(): {
|
|
@@ -44,5 +44,4 @@ declare const lastLoginMethodClient: (config?: LastLoginMethodClientConfig) => {
|
|
|
44
44
|
isLastUsedLoginMethod: (method: string) => boolean;
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
|
-
//#endregion
|
|
48
|
-
export { LastLoginMethodClientConfig, lastLoginMethodClient };
|
|
47
|
+
//#endregion
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
2
1
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as _$better_call0 from "better-call";
|
|
4
|
-
|
|
5
2
|
//#region src/plugins/last-login-method/index.d.ts
|
|
6
3
|
declare module "@better-auth/core" {
|
|
7
4
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -13,7 +10,7 @@ declare module "@better-auth/core" {
|
|
|
13
10
|
/**
|
|
14
11
|
* Configuration for tracking different authentication methods
|
|
15
12
|
*/
|
|
16
|
-
interface LastLoginMethodOptions {
|
|
13
|
+
export interface LastLoginMethodOptions {
|
|
17
14
|
/**
|
|
18
15
|
* Name of the cookie to store the last login method
|
|
19
16
|
* @default "better-auth.last_used_login_method"
|
|
@@ -57,10 +54,10 @@ interface LastLoginMethodOptions {
|
|
|
57
54
|
/**
|
|
58
55
|
* Plugin to track the last used login method
|
|
59
56
|
*/
|
|
60
|
-
declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O | undefined) => {
|
|
57
|
+
export declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O | undefined) => {
|
|
61
58
|
id: "last-login-method";
|
|
62
59
|
version: string;
|
|
63
|
-
init(ctx:
|
|
60
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
64
61
|
options: {
|
|
65
62
|
databaseHooks: {
|
|
66
63
|
user: {
|
|
@@ -107,7 +104,7 @@ declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O
|
|
|
107
104
|
hooks: {
|
|
108
105
|
after: {
|
|
109
106
|
matcher(): true;
|
|
110
|
-
handler:
|
|
107
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
111
108
|
}[];
|
|
112
109
|
};
|
|
113
110
|
schema: O["storeInDatabase"] extends true ? {
|
|
@@ -123,5 +120,4 @@ declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O
|
|
|
123
120
|
} : undefined;
|
|
124
121
|
options: NoInfer<O>;
|
|
125
122
|
};
|
|
126
|
-
//#endregion
|
|
127
|
-
export { LastLoginMethodOptions, lastLoginMethod };
|
|
123
|
+
//#endregion
|
|
@@ -30,7 +30,7 @@ const lastLoginMethod = (userConfig) => {
|
|
|
30
30
|
const config = {
|
|
31
31
|
...userConfig,
|
|
32
32
|
cookieName: userConfig?.cookieName ?? "better-auth.last_used_login_method",
|
|
33
|
-
maxAge: userConfig?.maxAge ??
|
|
33
|
+
maxAge: userConfig?.maxAge ?? 2592e3
|
|
34
34
|
};
|
|
35
35
|
return {
|
|
36
36
|
id: "last-login-method",
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { magicLink } from "./index.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/plugins/magic-link/client.d.ts
|
|
4
|
-
declare const magicLinkClient: () => {
|
|
3
|
+
export declare const magicLinkClient: () => {
|
|
5
4
|
id: "magic-link";
|
|
6
5
|
version: string;
|
|
7
6
|
$InferServerPlugin: ReturnType<typeof magicLink>;
|
|
8
7
|
};
|
|
9
|
-
//#endregion
|
|
10
|
-
export { magicLinkClient };
|
|
8
|
+
//#endregion
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Awaitable, GenericEndpointContext } from "@better-auth/core";
|
|
2
|
-
import * as _$better_call0 from "better-call";
|
|
3
2
|
import * as z from "zod";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/magic-link/index.d.ts
|
|
6
4
|
declare module "@better-auth/core" {
|
|
7
5
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -10,7 +8,7 @@ declare module "@better-auth/core" {
|
|
|
10
8
|
};
|
|
11
9
|
}
|
|
12
10
|
}
|
|
13
|
-
interface MagicLinkOptions {
|
|
11
|
+
export interface MagicLinkOptions {
|
|
14
12
|
/**
|
|
15
13
|
* Time in seconds until the magic link expires.
|
|
16
14
|
* @default (60 * 5) // 5 minutes
|
|
@@ -71,7 +69,7 @@ interface MagicLinkOptions {
|
|
|
71
69
|
hash: (token: string) => Promise<string>;
|
|
72
70
|
}) | undefined;
|
|
73
71
|
}
|
|
74
|
-
declare const magicLink: (options: MagicLinkOptions) => {
|
|
72
|
+
export declare const magicLink: (options: MagicLinkOptions) => {
|
|
75
73
|
id: "magic-link";
|
|
76
74
|
version: string;
|
|
77
75
|
endpoints: {
|
|
@@ -90,10 +88,10 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
90
88
|
*
|
|
91
89
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/sign-in#api-method-sign-in-magic-link)
|
|
92
90
|
*/
|
|
93
|
-
signInMagicLink:
|
|
91
|
+
signInMagicLink: import("better-call").StrictEndpoint<"/sign-in/magic-link", {
|
|
94
92
|
method: "POST";
|
|
95
93
|
requireHeaders: true;
|
|
96
|
-
use:
|
|
94
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
97
95
|
body: z.ZodObject<{
|
|
98
96
|
email: z.ZodEmail;
|
|
99
97
|
name: z.ZodOptional<z.ZodString>;
|
|
@@ -143,7 +141,7 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
143
141
|
*
|
|
144
142
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/magic-link#api-method-magic-link-verify)
|
|
145
143
|
*/
|
|
146
|
-
magicLinkVerify:
|
|
144
|
+
magicLinkVerify: import("better-call").StrictEndpoint<"/magic-link/verify", {
|
|
147
145
|
method: "GET";
|
|
148
146
|
query: z.ZodObject<{
|
|
149
147
|
token: z.ZodString;
|
|
@@ -151,7 +149,7 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
151
149
|
errorCallbackURL: z.ZodOptional<z.ZodString>;
|
|
152
150
|
newUserCallbackURL: z.ZodOptional<z.ZodString>;
|
|
153
151
|
}, z.core.$strip>;
|
|
154
|
-
use:
|
|
152
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>[];
|
|
155
153
|
requireHeaders: true;
|
|
156
154
|
metadata: {
|
|
157
155
|
openapi: {
|
|
@@ -209,5 +207,4 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
209
207
|
}[];
|
|
210
208
|
options: MagicLinkOptions;
|
|
211
209
|
};
|
|
212
|
-
//#endregion
|
|
213
|
-
export { MagicLinkOptions, magicLink };
|
|
210
|
+
//#endregion
|
|
@@ -161,7 +161,8 @@ const magicLink = (options) => {
|
|
|
161
161
|
throw ctx.redirect(errorCallbackURL.toString());
|
|
162
162
|
}
|
|
163
163
|
const newUserCallbackURL = new URL(ctx.query.newUserCallbackURL || callbackURL, ctx.context.baseURL).toString();
|
|
164
|
-
const
|
|
164
|
+
const storedToken = await storeToken(ctx, token);
|
|
165
|
+
const identifier = magicLinkIdentifier(storedToken);
|
|
165
166
|
const pendingValue = await ctx.context.internalAdapter.findVerificationValue(identifier);
|
|
166
167
|
if (!pendingValue || !parseMagicLinkRecord(pendingValue.value)?.success) redirectWithError("INVALID_TOKEN");
|
|
167
168
|
const tokenValue = await ctx.context.internalAdapter.consumeVerificationValue(identifier);
|
|
@@ -171,22 +172,24 @@ const magicLink = (options) => {
|
|
|
171
172
|
const { email, name } = record.data;
|
|
172
173
|
let isNewUser = false;
|
|
173
174
|
let user = await ctx.context.internalAdapter.findUserByEmail(email).then((res) => res?.user);
|
|
174
|
-
if (!user)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
175
|
+
if (!user) {
|
|
176
|
+
if (!opts.disableSignUp) {
|
|
177
|
+
let newUser;
|
|
178
|
+
try {
|
|
179
|
+
newUser = await ctx.context.internalAdapter.createUser({
|
|
180
|
+
email,
|
|
181
|
+
emailVerified: true,
|
|
182
|
+
name: name || ""
|
|
183
|
+
}, { method: "magic-link" });
|
|
184
|
+
} catch (e) {
|
|
185
|
+
if (isAPIError(e) && e.body?.code) redirectWithError(e.body.code, e.body.message);
|
|
186
|
+
throw e;
|
|
187
|
+
}
|
|
188
|
+
isNewUser = true;
|
|
189
|
+
user = newUser;
|
|
190
|
+
if (!user) redirectWithError("failed_to_create_user");
|
|
191
|
+
} else redirectWithError("new_user_signup_disabled");
|
|
192
|
+
}
|
|
190
193
|
if (!user.emailVerified) {
|
|
191
194
|
const promotedUser = await revokeUnprovenAccountAccess(ctx, user.id);
|
|
192
195
|
if (!promotedUser) redirectWithError("user_not_found");
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { MULTI_SESSION_ERROR_CODES } from "./error-codes.mjs";
|
|
2
2
|
import { MultiSessionConfig, multiSession } from "./index.mjs";
|
|
3
|
-
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/multi-session/client.d.ts
|
|
6
|
-
declare const multiSessionClient: () => {
|
|
4
|
+
export declare const multiSessionClient: () => {
|
|
7
5
|
id: "multi-session";
|
|
8
6
|
version: string;
|
|
9
7
|
$InferServerPlugin: ReturnType<typeof multiSession>;
|
|
@@ -12,8 +10,8 @@ declare const multiSessionClient: () => {
|
|
|
12
10
|
signal: "$sessionSignal";
|
|
13
11
|
}[];
|
|
14
12
|
$ERROR_CODES: {
|
|
15
|
-
INVALID_SESSION_TOKEN:
|
|
13
|
+
INVALID_SESSION_TOKEN: import("@better-auth/core/utils/error-codes").RawError<"INVALID_SESSION_TOKEN">;
|
|
16
14
|
};
|
|
17
15
|
};
|
|
18
16
|
//#endregion
|
|
19
|
-
export {
|
|
17
|
+
export { MULTI_SESSION_ERROR_CODES, type MultiSessionConfig };
|