better-auth 1.8.0-beta.2 → 1.8.0-beta.4
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 +7 -5
- 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/parser.mjs +1 -11
- 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 +16 -9
- package/dist/context/create-context.mjs +7 -7
- package/dist/context/helpers.mjs +9 -7
- package/dist/context/secret-utils.mjs +3 -3
- 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 +124 -129
- package/dist/plugins/admin/admin.mjs +4 -4
- package/dist/plugins/admin/client.d.mts +33 -32
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +26 -28
- package/dist/plugins/admin/error-codes.mjs +2 -1
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/index.mjs +1 -2
- package/dist/plugins/admin/routes.mjs +1 -0
- 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 +9 -8
- package/dist/plugins/device-authorization/routes.d.mts +11 -9
- 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/gumroad.mjs +1 -1
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +5 -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/patreon.mjs +2 -2
- package/dist/plugins/generic-oauth/providers/slack.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/slack.mjs +5 -2
- 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 +164 -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/index.mjs +5 -18
- 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/client/types.d.mts
CHANGED
|
@@ -3,9 +3,9 @@ import { StripEmptyObjects, UnionToIntersection } from "../types/helper.mjs";
|
|
|
3
3
|
import { InferRoutes } from "./path-to-object.mjs";
|
|
4
4
|
import { Session as Session$1, User as User$1 } from "../types/models.mjs";
|
|
5
5
|
import { Auth } from "../types/auth.mjs";
|
|
6
|
+
import "../types/index.mjs";
|
|
6
7
|
import { BetterAuthClientOptions as BetterAuthClientOptions$1, BetterAuthClientPlugin, ClientAtomListener as ClientAtomListener$1, ClientStore as ClientStore$1 } from "@better-auth/core";
|
|
7
8
|
import { DBFieldAttribute, InferDBFieldsOutput } from "@better-auth/core/db";
|
|
8
|
-
|
|
9
9
|
//#region src/client/types.d.ts
|
|
10
10
|
type ClientPluginError<K extends string = string> = {
|
|
11
11
|
readonly code: K;
|
|
@@ -16,36 +16,36 @@ type InferPluginEndpoints<Plugins> = Plugins extends Array<infer Pl> ? UnionToIn
|
|
|
16
16
|
} ? Plug extends {
|
|
17
17
|
endpoints?: infer Endpoints;
|
|
18
18
|
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {}> : {};
|
|
19
|
-
type InferClientAPI<O extends BetterAuthClientOptions$1> = InferRoutes<O["plugins"] extends Array<any> ? Omit<Auth["api"], keyof InferPluginEndpoints<O["plugins"]>> & InferPluginEndpoints<O["plugins"]> : Auth["api"], O>;
|
|
20
|
-
type InferActions<O extends BetterAuthClientOptions$1> = (O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends {
|
|
19
|
+
export type InferClientAPI<O extends BetterAuthClientOptions$1> = InferRoutes<O["plugins"] extends Array<any> ? Omit<Auth["api"], keyof InferPluginEndpoints<O["plugins"]>> & InferPluginEndpoints<O["plugins"]> : Auth["api"], O>;
|
|
20
|
+
export type InferActions<O extends BetterAuthClientOptions$1> = (O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends {
|
|
21
21
|
getActions?: infer GetActions;
|
|
22
22
|
} ? GetActions extends ((...args: any) => infer Actions) ? Actions : {} : {}> : {}) & InferRoutes<O["$InferAuth"] extends {
|
|
23
23
|
plugins: infer Plugins;
|
|
24
24
|
} ? Plugins extends Array<infer Plugin> ? Plugin extends {
|
|
25
25
|
endpoints?: infer Endpoints;
|
|
26
26
|
} ? Endpoints extends Record<string, unknown> ? Endpoints : {} : {} : {} : {}, O>;
|
|
27
|
-
type InferErrorCodes<O extends BetterAuthClientOptions$1> = O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends {
|
|
27
|
+
export type InferErrorCodes<O extends BetterAuthClientOptions$1> = O["plugins"] extends Array<infer Plugin> ? UnionToIntersection<Plugin extends {
|
|
28
28
|
$InferServerPlugin?: infer ServerPlugin;
|
|
29
29
|
} ? ServerPlugin extends {
|
|
30
30
|
$ERROR_CODES?: infer E;
|
|
31
|
-
} ? { [K in keyof E & string]: E[K] extends ClientPluginError ? ClientPluginError<K> : never } : {} : {}> : {};
|
|
31
|
+
} ? { [K in keyof E & string]: E[K] extends ClientPluginError ? ClientPluginError<K> : never; } : {} : {}> : {};
|
|
32
32
|
/**
|
|
33
33
|
* signals are just used to recall a computed value.
|
|
34
34
|
* as a convention they start with "$"
|
|
35
35
|
*/
|
|
36
|
-
type IsSignal<T> = T extends `$${infer _}` ? true : false;
|
|
37
|
-
type InferSessionFromClient<O extends BetterAuthClientOptions$1> = StripEmptyObjects<Session$1 & UnionToIntersection<InferAdditionalFromClient<O, "session", "output">>>;
|
|
38
|
-
type InferUserFromClient<O extends BetterAuthClientOptions$1> = StripEmptyObjects<User$1 & UnionToIntersection<InferAdditionalFromClient<O, "user", "output">>>;
|
|
39
|
-
type InferAdditionalFromClient<Options extends BetterAuthClientOptions$1, Key extends string, Format extends "input" | "output" = "output"> = Options["plugins"] extends Array<infer Plugin> ? Plugin extends {
|
|
36
|
+
export type IsSignal<T> = T extends `$${infer _}` ? true : false;
|
|
37
|
+
export type InferSessionFromClient<O extends BetterAuthClientOptions$1> = StripEmptyObjects<Session$1 & UnionToIntersection<InferAdditionalFromClient<O, "session", "output">>>;
|
|
38
|
+
export type InferUserFromClient<O extends BetterAuthClientOptions$1> = StripEmptyObjects<User$1 & UnionToIntersection<InferAdditionalFromClient<O, "user", "output">>>;
|
|
39
|
+
export type InferAdditionalFromClient<Options extends BetterAuthClientOptions$1, Key extends string, Format extends "input" | "output" = "output"> = Options["plugins"] extends Array<infer Plugin> ? Plugin extends {
|
|
40
40
|
$InferServerPlugin?: infer ServerPlugin;
|
|
41
41
|
} ? ServerPlugin extends {
|
|
42
42
|
schema?: infer Schema;
|
|
43
43
|
} ? Schema extends Record<Key, {
|
|
44
44
|
fields: infer Fields;
|
|
45
45
|
}> ? Fields extends Record<string, DBFieldAttribute> ? Format extends "input" ? InferFieldsInputClient<Fields> : InferDBFieldsOutput<Fields> : {} : {} : {} : {} : {};
|
|
46
|
-
type SessionQueryParams = {
|
|
46
|
+
export type SessionQueryParams = {
|
|
47
47
|
disableCookieCache?: boolean | undefined;
|
|
48
48
|
disableRefresh?: boolean | undefined;
|
|
49
49
|
};
|
|
50
50
|
//#endregion
|
|
51
|
-
export {
|
|
51
|
+
export type { BetterAuthClientOptions$1 as BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener$1 as ClientAtomListener, ClientStore$1 as ClientStore };
|
|
@@ -5,13 +5,12 @@ import { BetterAuthClientOptions } from "@better-auth/core";
|
|
|
5
5
|
import { BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
6
6
|
import { Atom } from "nanostores";
|
|
7
7
|
import { BetterFetchError, BetterFetchResponse } from "@better-fetch/fetch";
|
|
8
|
-
|
|
9
8
|
//#region src/client/vanilla.d.ts
|
|
10
9
|
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
|
|
11
10
|
plugins: Array<infer Plugin>;
|
|
12
11
|
} ? UnionToIntersection<Plugin extends {
|
|
13
12
|
getAtoms?: infer GetAtoms;
|
|
14
|
-
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: Atoms[key] } : {} : {} : {}> : {};
|
|
13
|
+
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: Atoms[key]; } : {} : {} : {}> : {};
|
|
15
14
|
type ClientConfig = ReturnType<typeof getClientConfig>;
|
|
16
15
|
type ClientSession<Option extends BetterAuthClientOptions> = InferClientAPI<Option> extends {
|
|
17
16
|
getSession: () => Promise<infer Res>;
|
|
@@ -19,7 +18,7 @@ type ClientSession<Option extends BetterAuthClientOptions> = InferClientAPI<Opti
|
|
|
19
18
|
/**
|
|
20
19
|
* Client returned by `createAuthClient`.
|
|
21
20
|
*/
|
|
22
|
-
type AuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
21
|
+
export type AuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
23
22
|
hydrateSession(session: NonNullable<ClientSession<Option>> | null): void;
|
|
24
23
|
useSession: Atom<{
|
|
25
24
|
data: ClientSession<Option>;
|
|
@@ -37,6 +36,6 @@ type AuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<In
|
|
|
37
36
|
};
|
|
38
37
|
$ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>;
|
|
39
38
|
};
|
|
40
|
-
declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): AuthClient<Option>;
|
|
39
|
+
export declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): AuthClient<Option>;
|
|
41
40
|
//#endregion
|
|
42
|
-
export {
|
|
41
|
+
export {};
|
package/dist/client/vanilla.mjs
CHANGED
|
@@ -6,13 +6,14 @@ function createAuthClient(options) {
|
|
|
6
6
|
const { pluginPathMethods, pluginsActions, pluginsAtoms, hydrateSession, $fetch, atomListeners, $store } = getClientConfig(options);
|
|
7
7
|
const resolvedHooks = {};
|
|
8
8
|
for (const [key, value] of Object.entries(pluginsAtoms)) resolvedHooks[`use${capitalizeFirstLetter(key)}`] = value;
|
|
9
|
-
|
|
9
|
+
const routes = {
|
|
10
10
|
...pluginsActions,
|
|
11
11
|
...resolvedHooks,
|
|
12
12
|
hydrateSession,
|
|
13
13
|
$fetch,
|
|
14
14
|
$store
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
|
+
return createDynamicPathProxy(routes, $fetch, pluginPathMethods, pluginsAtoms, atomListeners);
|
|
16
17
|
}
|
|
17
18
|
//#endregion
|
|
18
19
|
export { createAuthClient };
|
|
@@ -5,15 +5,14 @@ import { BetterAuthClientOptions } from "@better-auth/core";
|
|
|
5
5
|
import { BASE_ERROR_CODES } from "@better-auth/core/error";
|
|
6
6
|
import { BetterFetchError, BetterFetchResponse } from "@better-fetch/fetch";
|
|
7
7
|
import { DeepReadonly, Ref, WatchSource } from "vue";
|
|
8
|
-
export * from "nanostores";
|
|
9
|
-
export * from "@better-fetch/fetch";
|
|
10
|
-
|
|
8
|
+
export type * from "nanostores";
|
|
9
|
+
export type * from "@better-fetch/fetch";
|
|
11
10
|
//#region src/client/vue/index.d.ts
|
|
12
11
|
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
|
|
13
12
|
plugins: Array<infer Plugin>;
|
|
14
13
|
} ? UnionToIntersection<Plugin extends {
|
|
15
14
|
getAtoms?: infer GetAtoms;
|
|
16
|
-
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => DeepReadonly<Ref<ReturnType<Atoms[key]["get"]
|
|
15
|
+
} ? GetAtoms extends ((fetch: any) => infer Atoms) ? Atoms extends Record<string, any> ? { [key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: () => DeepReadonly<Ref<ReturnType<Atoms[key]["get"]>>>; } : {} : {} : {}> : {};
|
|
17
16
|
type ClientConfig = ReturnType<typeof getClientConfig>;
|
|
18
17
|
type ClientSession<Option extends BetterAuthClientOptions> = InferClientAPI<Option> extends {
|
|
19
18
|
getSession: () => Promise<infer Res>;
|
|
@@ -51,7 +50,7 @@ type SessionFetchResult<Option extends BetterAuthClientOptions> = {
|
|
|
51
50
|
/**
|
|
52
51
|
* Vue client returned by `createAuthClient`.
|
|
53
52
|
*/
|
|
54
|
-
type VueAuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
53
|
+
export type VueAuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection<InferResolvedHooks<Option>> & InferClientAPI<Option> & InferActions<Option> & {
|
|
55
54
|
hydrateSession(session: NonNullable<ClientSession<Option>> | null): void;
|
|
56
55
|
useSession(): VueSessionState<Option>;
|
|
57
56
|
useSession(useFetch: SessionFetch): Promise<SessionFetchResult<Option>>;
|
|
@@ -62,6 +61,6 @@ type VueAuthClient<Option extends BetterAuthClientOptions> = UnionToIntersection
|
|
|
62
61
|
$store: ClientConfig["$store"];
|
|
63
62
|
$ERROR_CODES: PrettifyDeep<InferErrorCodes<Option> & typeof BASE_ERROR_CODES>;
|
|
64
63
|
};
|
|
65
|
-
declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): VueAuthClient<Option>;
|
|
64
|
+
export declare function createAuthClient<Option extends BetterAuthClientOptions>(options?: Option | undefined): VueAuthClient<Option>;
|
|
66
65
|
//#endregion
|
|
67
|
-
export { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects,
|
|
66
|
+
export type { ExtractPluginField, HasRequiredKeys, InferPluginFieldFromTuple, IsAny, OverrideMerge, Prettify, PrettifyDeep, RequiredKeysOf, StripEmptyObjects, UnionToIntersection };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { trimTrailingSlashes } from "../../utils/url.mjs";
|
|
1
2
|
import { getClientConfig } from "../config.mjs";
|
|
2
3
|
import { createDynamicPathProxy } from "../proxy.mjs";
|
|
3
4
|
import { useStore } from "./vue-store.mjs";
|
|
@@ -16,18 +17,23 @@ function toHeadersInit(headers) {
|
|
|
16
17
|
}
|
|
17
18
|
function createAuthClient(options) {
|
|
18
19
|
const { baseURL, pluginPathMethods, pluginsActions, pluginsAtoms, hydrateSession, $sessionSignal, $fetch, $store, atomListeners } = getClientConfig(options, false);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const baseURLKey = options?.baseURL || "inferred";
|
|
21
|
+
const basePath = options?.basePath ?? "/api/auth";
|
|
22
|
+
const sessionCacheKey = `better-auth:session:${baseURLKey}:${basePath}`;
|
|
23
|
+
const sessionPath = trimTrailingSlashes(basePath.startsWith("/") ? basePath : `/${basePath}`);
|
|
24
|
+
/**
|
|
25
|
+
* Stays relative without an explicit `baseURL` so the SSR session fetch
|
|
26
|
+
* forwards the incoming cookies.
|
|
27
|
+
*
|
|
28
|
+
* @see https://nuxt.com/docs/4.x/getting-started/data-fetching
|
|
29
|
+
*/
|
|
30
|
+
const sessionURL = `${options?.baseURL ? baseURL : sessionPath}/get-session`;
|
|
25
31
|
const resolvedHooks = {};
|
|
26
32
|
for (const [key, value] of Object.entries(pluginsAtoms)) resolvedHooks[getAtomKey(key)] = () => useStore(value);
|
|
27
33
|
function useSession(useFetch) {
|
|
28
34
|
if (useFetch) {
|
|
29
35
|
const sessionSignal = useStore($sessionSignal);
|
|
30
|
-
return useFetch(
|
|
36
|
+
return useFetch(sessionURL, {
|
|
31
37
|
headers: toHeadersInit(options?.fetchOptions?.headers),
|
|
32
38
|
key: sessionCacheKey,
|
|
33
39
|
watch: [sessionSignal]
|
|
@@ -41,14 +47,15 @@ function createAuthClient(options) {
|
|
|
41
47
|
}
|
|
42
48
|
return resolvedHooks.useSession();
|
|
43
49
|
}
|
|
44
|
-
|
|
50
|
+
const routes = {
|
|
45
51
|
...pluginsActions,
|
|
46
52
|
...resolvedHooks,
|
|
47
53
|
hydrateSession,
|
|
48
54
|
useSession,
|
|
49
55
|
$fetch,
|
|
50
56
|
$store
|
|
51
|
-
}
|
|
57
|
+
};
|
|
58
|
+
return createDynamicPathProxy(routes, $fetch, pluginPathMethods, pluginsAtoms, atomListeners);
|
|
52
59
|
}
|
|
53
60
|
//#endregion
|
|
54
61
|
export { createAuthClient };
|
|
@@ -19,7 +19,7 @@ import { runtimeSchemaCheckFor, schemaCheckFor } from "@better-auth/core/db/inte
|
|
|
19
19
|
import { socialProviders } from "@better-auth/core/social-providers";
|
|
20
20
|
import { findInvalidTrustedProxies } from "@better-auth/core/utils/ip";
|
|
21
21
|
import { createTelemetry } from "@better-auth/telemetry";
|
|
22
|
-
import defu
|
|
22
|
+
import defu from "defu";
|
|
23
23
|
//#region src/context/create-context.ts
|
|
24
24
|
/**
|
|
25
25
|
* Estimates the entropy of a string in bits.
|
|
@@ -46,13 +46,13 @@ function validateSecret(secret, logger) {
|
|
|
46
46
|
}
|
|
47
47
|
async function createAuthContext(adapter, options, getDatabaseType) {
|
|
48
48
|
const isStateful = hasServerSessionStore(options);
|
|
49
|
-
if (!isStateful) options = defu
|
|
49
|
+
if (!isStateful) options = defu(options, { session: { cookieCache: {
|
|
50
50
|
enabled: true,
|
|
51
51
|
strategy: "jwe",
|
|
52
52
|
refreshCache: true,
|
|
53
|
-
maxAge: options.session?.expiresIn ||
|
|
53
|
+
maxAge: options.session?.expiresIn || 604800
|
|
54
54
|
} } });
|
|
55
|
-
if (!options.database) options = defu
|
|
55
|
+
if (!options.database) options = defu(options, { account: { storeAccountCookie: true } });
|
|
56
56
|
const plugins = options.plugins || [];
|
|
57
57
|
const internalPlugins = getInternalPlugins(options);
|
|
58
58
|
const logger = createLogger(options.logger);
|
|
@@ -144,9 +144,9 @@ Most of the features of Better Auth will not work correctly.`);
|
|
|
144
144
|
return this.trustedOrigins.some((origin) => matchesOriginPattern(url, origin, settings));
|
|
145
145
|
},
|
|
146
146
|
sessionConfig: {
|
|
147
|
-
updateAge: options.session?.updateAge !== void 0 ? options.session.updateAge :
|
|
148
|
-
expiresIn: options.session?.expiresIn ||
|
|
149
|
-
freshAge: options.session?.freshAge === void 0 ?
|
|
147
|
+
updateAge: options.session?.updateAge !== void 0 ? options.session.updateAge : 86400,
|
|
148
|
+
expiresIn: options.session?.expiresIn || 604800,
|
|
149
|
+
freshAge: options.session?.freshAge === void 0 ? 86400 : options.session.freshAge,
|
|
150
150
|
cookieRefreshCache: (() => {
|
|
151
151
|
const refreshCache = options.session?.cookieCache?.refreshCache;
|
|
152
152
|
const maxAge = options.session?.cookieCache?.maxAge || 300;
|
package/dist/context/helpers.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { createCookieGetter, getCookies } from "../cookies/index.mjs";
|
|
|
4
4
|
import { createInternalAdapter } from "../db/internal-adapter.mjs";
|
|
5
5
|
import { env } from "@better-auth/core/env";
|
|
6
6
|
import { BetterAuthError } from "@better-auth/core/error";
|
|
7
|
-
import { defu } from "defu";
|
|
7
|
+
import { defu as defu$1 } from "defu";
|
|
8
8
|
import { isLoopbackHost } from "@better-auth/core/utils/host";
|
|
9
9
|
//#region src/context/helpers.ts
|
|
10
10
|
async function runPluginInit(context) {
|
|
@@ -25,7 +25,7 @@ async function runPluginInit(context) {
|
|
|
25
25
|
hooks: databaseHooks
|
|
26
26
|
});
|
|
27
27
|
if (trustedOrigins) pluginTrustedOrigins.push(trustedOrigins);
|
|
28
|
-
options = defu(options, restOpts);
|
|
28
|
+
options = defu$1(options, restOpts);
|
|
29
29
|
}
|
|
30
30
|
if (result.context) Object.assign(context, result.context);
|
|
31
31
|
}
|
|
@@ -115,7 +115,8 @@ function resolveDynamicTrustedProxyHeaders(options) {
|
|
|
115
115
|
*/
|
|
116
116
|
async function resolveRequestContext(ctx, source, trustedProxyHeaders) {
|
|
117
117
|
const dynamicBaseURLConfig = ctx.options.baseURL;
|
|
118
|
-
const
|
|
118
|
+
const basePath = ctx.options.basePath || "/api/auth";
|
|
119
|
+
const baseURL = resolveBaseURL(dynamicBaseURLConfig, basePath, source, void 0, trustedProxyHeaders);
|
|
119
120
|
if (!baseURL) throw new BetterAuthError("Could not resolve base URL from request. Check your allowedHosts config.");
|
|
120
121
|
const resolved = Object.create(Object.getPrototypeOf(ctx), Object.getOwnPropertyDescriptors(ctx));
|
|
121
122
|
resolved.baseURL = baseURL;
|
|
@@ -129,10 +130,11 @@ async function resolveRequestContext(ctx, source, trustedProxyHeaders) {
|
|
|
129
130
|
};
|
|
130
131
|
const needsRequest = typeof ctx.options.trustedOrigins === "function" || typeof ctx.options.account?.accountLinking?.trustedProviders === "function";
|
|
131
132
|
let callbackRequest;
|
|
132
|
-
if (needsRequest)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
if (needsRequest) {
|
|
134
|
+
if (isRequestLike(source)) callbackRequest = source;
|
|
135
|
+
else if (source) callbackRequest = new Request(baseURL, { headers: source });
|
|
136
|
+
else callbackRequest = void 0;
|
|
137
|
+
} else callbackRequest = void 0;
|
|
136
138
|
resolved.trustedOrigins = await getTrustedOrigins(trustedOriginOptions, callbackRequest);
|
|
137
139
|
resolved.trustedProviders = await getTrustedProviders(resolved.options, callbackRequest);
|
|
138
140
|
if (ctx.options.advanced?.crossSubDomainCookies?.enabled) {
|
|
@@ -12,12 +12,12 @@ function estimateEntropy(str) {
|
|
|
12
12
|
}
|
|
13
13
|
function parseSecretsEnv(envValue) {
|
|
14
14
|
if (!envValue) return null;
|
|
15
|
-
return envValue.split(",").map((entry) => {
|
|
15
|
+
return envValue.split(",").map((entry, index) => {
|
|
16
16
|
entry = entry.trim();
|
|
17
17
|
const colonIdx = entry.indexOf(":");
|
|
18
|
-
if (colonIdx === -1) throw new BetterAuthError(`Invalid BETTER_AUTH_SECRETS entry
|
|
18
|
+
if (colonIdx === -1) throw new BetterAuthError(`Invalid BETTER_AUTH_SECRETS entry at position ${index + 1}. Expected format: "<version>:<secret>"`);
|
|
19
19
|
const version = parseInt(entry.slice(0, colonIdx), 10);
|
|
20
|
-
if (!Number.isInteger(version) || version < 0) throw new BetterAuthError(`Invalid version in BETTER_AUTH_SECRETS
|
|
20
|
+
if (!Number.isInteger(version) || version < 0) throw new BetterAuthError(`Invalid version in BETTER_AUTH_SECRETS entry at position ${index + 1}. Version must be a non-negative integer.`);
|
|
21
21
|
const value = entry.slice(colonIdx + 1).trim();
|
|
22
22
|
if (!value) throw new BetterAuthError(`Empty secret value for version ${version} in BETTER_AUTH_SECRETS.`);
|
|
23
23
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/cookies/cookie-utils.d.ts
|
|
2
|
-
interface CookieAttributes {
|
|
2
|
+
export interface CookieAttributes {
|
|
3
3
|
value: string;
|
|
4
4
|
"max-age"?: number | undefined;
|
|
5
5
|
expires?: Date | undefined;
|
|
@@ -21,24 +21,24 @@ interface ParsedCookieOptions {
|
|
|
21
21
|
partitioned?: boolean | undefined;
|
|
22
22
|
sameSite?: CookieAttributes["samesite"];
|
|
23
23
|
}
|
|
24
|
-
declare const SECURE_COOKIE_PREFIX = "__Secure-";
|
|
25
|
-
declare const HOST_COOKIE_PREFIX = "__Host-";
|
|
24
|
+
export declare const SECURE_COOKIE_PREFIX = "__Secure-";
|
|
25
|
+
export declare const HOST_COOKIE_PREFIX = "__Host-";
|
|
26
26
|
/**
|
|
27
27
|
* Remove __Secure- or __Host- prefix from cookie name.
|
|
28
28
|
*/
|
|
29
|
-
declare function stripSecureCookiePrefix(cookieName: string): string;
|
|
29
|
+
export declare function stripSecureCookiePrefix(cookieName: string): string;
|
|
30
30
|
/**
|
|
31
31
|
* Split a comma-joined `Set-Cookie` header string into individual cookies.
|
|
32
32
|
*/
|
|
33
|
-
declare function splitSetCookieHeader(setCookie: string): string[];
|
|
34
|
-
declare function parseSetCookieHeader(setCookie: string): Map<string, CookieAttributes>;
|
|
35
|
-
declare function toCookieOptions(attributes: CookieAttributes): ParsedCookieOptions;
|
|
33
|
+
export declare function splitSetCookieHeader(setCookie: string): string[];
|
|
34
|
+
export declare function parseSetCookieHeader(setCookie: string): Map<string, CookieAttributes>;
|
|
35
|
+
export declare function toCookieOptions(attributes: CookieAttributes): ParsedCookieOptions;
|
|
36
36
|
/**
|
|
37
37
|
* Cookie-name token char set per RFC 7230 §3.2.6.
|
|
38
38
|
*
|
|
39
39
|
* @see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6
|
|
40
40
|
*/
|
|
41
|
-
declare const cookieNameRegex: RegExp;
|
|
41
|
+
export declare const cookieNameRegex: RegExp;
|
|
42
42
|
/**
|
|
43
43
|
* Tolerates `;` separators without the SP that RFC 6265 §4.2.1 mandates,
|
|
44
44
|
* since proxies and runtimes commonly strip it. Silently drops entries
|
|
@@ -46,7 +46,7 @@ declare const cookieNameRegex: RegExp;
|
|
|
46
46
|
* cookie-octet (plus space and comma). Strips optional surrounding
|
|
47
47
|
* double-quotes per RFC 6265 §4.1.1.
|
|
48
48
|
*/
|
|
49
|
-
declare function parseCookies(cookie: string): Map<string, string>;
|
|
49
|
+
export declare function parseCookies(cookie: string): Map<string, string>;
|
|
50
50
|
/**
|
|
51
51
|
* Add or replace a cookie in the request `Cookie` header.
|
|
52
52
|
*
|
|
@@ -55,7 +55,7 @@ declare function parseCookies(cookie: string): Map<string, string>;
|
|
|
55
55
|
* breaks downstream cookie parsing. This builds the header value via
|
|
56
56
|
* parse-mutate-serialize.
|
|
57
57
|
*/
|
|
58
|
-
declare function setRequestCookie(headers: Headers, name: string, value: string): void;
|
|
58
|
+
export declare function setRequestCookie(headers: Headers, name: string, value: string): void;
|
|
59
59
|
/**
|
|
60
60
|
* Merge `Set-Cookie` header values into the target's `Cookie` header.
|
|
61
61
|
* Mutates `target`.
|
|
@@ -64,9 +64,9 @@ declare function setRequestCookie(headers: Headers, name: string, value: string)
|
|
|
64
64
|
* (expiration, domain/path scoping, ordering) are out of scope. Suitable
|
|
65
65
|
* for single-request proxy, middleware, and test contexts.
|
|
66
66
|
*/
|
|
67
|
-
declare function applySetCookies(target: Headers, setCookieValues: Iterable<string>): void;
|
|
68
|
-
declare function setCookieToHeader(headers: Headers): (context: {
|
|
67
|
+
export declare function applySetCookies(target: Headers, setCookieValues: Iterable<string>): void;
|
|
68
|
+
export declare function setCookieToHeader(headers: Headers): (context: {
|
|
69
69
|
response: Response;
|
|
70
70
|
}) => void;
|
|
71
71
|
//#endregion
|
|
72
|
-
export {
|
|
72
|
+
export {};
|
|
@@ -82,9 +82,7 @@ function parseSetCookieHeader(setCookie) {
|
|
|
82
82
|
case "partitioned":
|
|
83
83
|
attrObj.partitioned = true;
|
|
84
84
|
break;
|
|
85
|
-
default:
|
|
86
|
-
attrObj[normalizedAttrName] = attrValue ? attrValue.trim() : true;
|
|
87
|
-
break;
|
|
85
|
+
default: attrObj[normalizedAttrName] = attrValue ? attrValue.trim() : true;
|
|
88
86
|
}
|
|
89
87
|
});
|
|
90
88
|
cookies.set(name, attrObj);
|
package/dist/cookies/index.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Session, User } from "../types/models.mjs";
|
|
2
|
+
import "../types/index.mjs";
|
|
2
3
|
import { CookieAttributes, HOST_COOKIE_PREFIX, SECURE_COOKIE_PREFIX, applySetCookies, cookieNameRegex, parseCookies, parseSetCookieHeader, setCookieToHeader, setRequestCookie, splitSetCookieHeader, stripSecureCookiePrefix, toCookieOptions } from "./cookie-utils.mjs";
|
|
3
4
|
import { createSessionStore, getAccountCookie, getChunkedCookie, setAccountCookie } from "./session-store.mjs";
|
|
4
5
|
import { Awaitable, BetterAuthCookie, BetterAuthCookies, BetterAuthOptions, CookieCachePayload, GenericEndpointContext } from "@better-auth/core";
|
|
5
|
-
import * as _$better_call0 from "better-call";
|
|
6
6
|
import { CookieOptions } from "better-call";
|
|
7
7
|
import { JSONWebKeySet } from "jose";
|
|
8
|
-
|
|
9
8
|
//#region src/cookies/index.d.ts
|
|
10
|
-
declare function createCookieGetter(options: BetterAuthOptions): (cookieName: string, overrideAttributes?: Partial<CookieOptions>) => {
|
|
9
|
+
export declare function createCookieGetter(options: BetterAuthOptions): (cookieName: string, overrideAttributes?: Partial<CookieOptions>) => {
|
|
11
10
|
name: string;
|
|
12
11
|
attributes: {
|
|
13
12
|
domain?: string | undefined;
|
|
@@ -18,10 +17,10 @@ declare function createCookieGetter(options: BetterAuthOptions): (cookieName: st
|
|
|
18
17
|
secure: boolean;
|
|
19
18
|
sameSite: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
|
|
20
19
|
partitioned?: boolean;
|
|
21
|
-
prefix?:
|
|
20
|
+
prefix?: import("better-call").CookiePrefixOptions;
|
|
22
21
|
};
|
|
23
22
|
};
|
|
24
|
-
declare function getCookies(options: BetterAuthOptions): {
|
|
23
|
+
export declare function getCookies(options: BetterAuthOptions): {
|
|
25
24
|
sessionToken: {
|
|
26
25
|
name: string;
|
|
27
26
|
attributes: {
|
|
@@ -33,7 +32,7 @@ declare function getCookies(options: BetterAuthOptions): {
|
|
|
33
32
|
secure: boolean;
|
|
34
33
|
sameSite: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
|
|
35
34
|
partitioned?: boolean;
|
|
36
|
-
prefix?:
|
|
35
|
+
prefix?: import("better-call").CookiePrefixOptions;
|
|
37
36
|
};
|
|
38
37
|
};
|
|
39
38
|
/**
|
|
@@ -51,7 +50,7 @@ declare function getCookies(options: BetterAuthOptions): {
|
|
|
51
50
|
secure: boolean;
|
|
52
51
|
sameSite: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
|
|
53
52
|
partitioned?: boolean;
|
|
54
|
-
prefix?:
|
|
53
|
+
prefix?: import("better-call").CookiePrefixOptions;
|
|
55
54
|
};
|
|
56
55
|
};
|
|
57
56
|
dontRememberToken: {
|
|
@@ -65,7 +64,7 @@ declare function getCookies(options: BetterAuthOptions): {
|
|
|
65
64
|
secure: boolean;
|
|
66
65
|
sameSite: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
|
|
67
66
|
partitioned?: boolean;
|
|
68
|
-
prefix?:
|
|
67
|
+
prefix?: import("better-call").CookiePrefixOptions;
|
|
69
68
|
};
|
|
70
69
|
};
|
|
71
70
|
accountData: {
|
|
@@ -79,35 +78,35 @@ declare function getCookies(options: BetterAuthOptions): {
|
|
|
79
78
|
secure: boolean;
|
|
80
79
|
sameSite: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
|
|
81
80
|
partitioned?: boolean;
|
|
82
|
-
prefix?:
|
|
81
|
+
prefix?: import("better-call").CookiePrefixOptions;
|
|
83
82
|
};
|
|
84
83
|
};
|
|
85
84
|
};
|
|
86
|
-
declare function setCookieCache(ctx: GenericEndpointContext, session: {
|
|
85
|
+
export declare function setCookieCache(ctx: GenericEndpointContext, session: {
|
|
87
86
|
session: Session & Record<string, unknown>;
|
|
88
87
|
user: User;
|
|
89
88
|
}, dontRememberMe: boolean): Promise<void>;
|
|
90
|
-
declare function decodeCookieCache(ctx: GenericEndpointContext, value: string): Promise<{
|
|
89
|
+
export declare function decodeCookieCache(ctx: GenericEndpointContext, value: string): Promise<{
|
|
91
90
|
session: CookieCachePayload;
|
|
92
91
|
expiresAt: number;
|
|
93
92
|
} | null>;
|
|
94
|
-
declare function setSessionCookie(ctx: GenericEndpointContext, session: {
|
|
93
|
+
export declare function setSessionCookie(ctx: GenericEndpointContext, session: {
|
|
95
94
|
session: Session & Record<string, unknown>;
|
|
96
95
|
user: User;
|
|
97
96
|
}, dontRememberMe?: boolean | undefined, overrides?: Partial<CookieOptions> | undefined): Promise<void>;
|
|
98
97
|
/**
|
|
99
98
|
* Expires a cookie by setting `maxAge: 0` while preserving its attributes
|
|
100
99
|
*/
|
|
101
|
-
declare function expireCookie(ctx: GenericEndpointContext, cookie: BetterAuthCookie): void;
|
|
102
|
-
declare function deleteSessionCookie(ctx: GenericEndpointContext, skipDontRememberMe?: boolean | undefined): void;
|
|
103
|
-
type EligibleCookies = (string & {}) | (keyof BetterAuthCookies & {});
|
|
104
|
-
declare const getSessionCookie: (request: Request | Headers, config?: {
|
|
100
|
+
export declare function expireCookie(ctx: GenericEndpointContext, cookie: BetterAuthCookie): void;
|
|
101
|
+
export declare function deleteSessionCookie(ctx: GenericEndpointContext, skipDontRememberMe?: boolean | undefined): void;
|
|
102
|
+
export type EligibleCookies = (string & {}) | (keyof BetterAuthCookies & {});
|
|
103
|
+
export declare const getSessionCookie: (request: Request | Headers, config?: {
|
|
105
104
|
cookiePrefix?: string;
|
|
106
105
|
cookieName?: string;
|
|
107
106
|
path?: string;
|
|
108
107
|
} | undefined) => string | null;
|
|
109
108
|
type CookieCacheVersion = string | ((session: CookieCachePayload["session"], user: CookieCachePayload["user"]) => Awaitable<string>);
|
|
110
|
-
declare const getCookieCache: <S extends CookieCachePayload = CookieCachePayload>(request: Request | Headers, config?: {
|
|
109
|
+
export declare const getCookieCache: <S extends CookieCachePayload = CookieCachePayload>(request: Request | Headers, config?: {
|
|
111
110
|
cookiePrefix?: string;
|
|
112
111
|
cookieName?: string;
|
|
113
112
|
isSecure?: boolean;
|
|
@@ -121,4 +120,4 @@ declare const getCookieCache: <S extends CookieCachePayload = CookieCachePayload
|
|
|
121
120
|
version?: CookieCacheVersion;
|
|
122
121
|
} | undefined) => Promise<S | null>;
|
|
123
122
|
//#endregion
|
|
124
|
-
export { CookieAttributes,
|
|
123
|
+
export { CookieAttributes, HOST_COOKIE_PREFIX, SECURE_COOKIE_PREFIX, applySetCookies, cookieNameRegex, createSessionStore, getAccountCookie, getChunkedCookie, parseCookies, parseSetCookieHeader, setAccountCookie, setCookieToHeader, setRequestCookie, splitSetCookieHeader, stripSecureCookiePrefix, toCookieOptions };
|
package/dist/cookies/index.mjs
CHANGED
|
@@ -115,11 +115,13 @@ async function setCookieCache(ctx, session, dontRememberMe) {
|
|
|
115
115
|
sessionStore.setCookies(sessionStore.chunk(data, options));
|
|
116
116
|
if (ctx.context.options.account?.storeAccountCookie && !hasPendingSetCookie(ctx, ctx.context.authCookies.accountData.name)) {
|
|
117
117
|
const accountData = await getAccountCookie(ctx);
|
|
118
|
-
if (accountData)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
if (accountData) {
|
|
119
|
+
if (!shouldBindAccountCookieToSessionUser(ctx.context.options) || accountData.userId === session.user.id) await setAccountCookie(ctx, accountData);
|
|
120
|
+
else {
|
|
121
|
+
expireCookie(ctx, ctx.context.authCookies.accountData);
|
|
122
|
+
const accountStore = createAccountStore(ctx.context.authCookies.accountData.name, ctx.context.authCookies.accountData.attributes, ctx);
|
|
123
|
+
accountStore.setCookies(accountStore.clean());
|
|
124
|
+
}
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
@@ -300,7 +302,8 @@ const getCookieCache = async (request, config) => {
|
|
|
300
302
|
if (strategy === "jwe") {
|
|
301
303
|
const secret = config?.secret || env.BETTER_AUTH_SECRET;
|
|
302
304
|
if (!secret) throw new BetterAuthError("getCookieCache requires a secret to be provided. Either pass it as an option or set the BETTER_AUTH_SECRET environment variable");
|
|
303
|
-
const
|
|
305
|
+
const decoded = await symmetricDecodeJWT(sessionData, secret, "better-auth-session");
|
|
306
|
+
const payload = parseCookieCachePayload(decoded);
|
|
304
307
|
if (!payload) return null;
|
|
305
308
|
if (config?.version) {
|
|
306
309
|
if (!await matchesVersion(payload, config.version)) return null;
|
|
@@ -317,7 +320,8 @@ const getCookieCache = async (request, config) => {
|
|
|
317
320
|
else {
|
|
318
321
|
const secret = config?.secret || env.BETTER_AUTH_SECRET;
|
|
319
322
|
if (!secret) throw new BetterAuthError("getCookieCache requires a secret to be provided. Either pass it as an option or set the BETTER_AUTH_SECRET environment variable");
|
|
320
|
-
|
|
323
|
+
const decoded = await verifyJWT(sessionData, secret);
|
|
324
|
+
payload = parseCookieCachePayload(decoded);
|
|
321
325
|
}
|
|
322
326
|
if (!payload) return null;
|
|
323
327
|
if (config?.version) {
|
package/dist/cookies/jwt.mjs
CHANGED
|
@@ -31,7 +31,8 @@ async function verifySessionCookieJwtWithJwks(token, jwks, options) {
|
|
|
31
31
|
if (!key) return null;
|
|
32
32
|
const alg = key.alg ?? header.alg;
|
|
33
33
|
if (!alg) return null;
|
|
34
|
-
const
|
|
34
|
+
const publicKey = await importJWK(key, alg);
|
|
35
|
+
const { payload } = await jwtVerify(token, publicKey, {
|
|
35
36
|
...getSessionCookieJwtVerifyOptions(options),
|
|
36
37
|
algorithms: [alg]
|
|
37
38
|
});
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
2
2
|
import { CookieOptions } from "better-call";
|
|
3
|
+
import "zod";
|
|
3
4
|
//#region src/cookies/session-store.d.ts
|
|
4
5
|
interface Cookie {
|
|
5
6
|
name: string;
|
|
6
7
|
value: string;
|
|
7
8
|
attributes: CookieOptions;
|
|
8
9
|
}
|
|
9
|
-
declare const createSessionStore: (cookieName: string, cookieOptions: CookieOptions, ctx: GenericEndpointContext) => {
|
|
10
|
+
export declare const createSessionStore: (cookieName: string, cookieOptions: CookieOptions, ctx: GenericEndpointContext) => {
|
|
10
11
|
chunk(value: string, options?: Partial<CookieOptions>): Cookie[];
|
|
11
12
|
clean(): Cookie[];
|
|
12
13
|
setCookies(cookies: Cookie[]): void;
|
|
13
14
|
};
|
|
14
|
-
declare function getChunkedCookie(ctx: GenericEndpointContext, cookieName: string): string | null;
|
|
15
|
-
declare function setAccountCookie(c: GenericEndpointContext, accountData: Record<string, any>): Promise<void>;
|
|
16
|
-
declare function getAccountCookie(c: GenericEndpointContext): Promise<{
|
|
15
|
+
export declare function getChunkedCookie(ctx: GenericEndpointContext, cookieName: string): string | null;
|
|
16
|
+
export declare function setAccountCookie(c: GenericEndpointContext, accountData: Record<string, any>): Promise<void>;
|
|
17
|
+
export declare function getAccountCookie(c: GenericEndpointContext): Promise<{
|
|
17
18
|
id: string;
|
|
18
19
|
createdAt: Date;
|
|
19
20
|
updatedAt: Date;
|
|
@@ -29,4 +30,4 @@ declare function getAccountCookie(c: GenericEndpointContext): Promise<{
|
|
|
29
30
|
password?: string | null | undefined;
|
|
30
31
|
} | null>;
|
|
31
32
|
//#endregion
|
|
32
|
-
export {
|
|
33
|
+
export {};
|
|
@@ -24,7 +24,8 @@ const MAX_COOKIE_CHUNKS = 100;
|
|
|
24
24
|
* wire. Non-positive when the name and attributes alone overflow.
|
|
25
25
|
*/
|
|
26
26
|
function getMaxCookieValueSize(name, options) {
|
|
27
|
-
|
|
27
|
+
const overhead = serializeCookie(name, "", { ...options }).length;
|
|
28
|
+
return MAX_COOKIE_SIZE - overhead;
|
|
28
29
|
}
|
|
29
30
|
function parseCookieChunkIndex(cookieName, name) {
|
|
30
31
|
const prefix = `${cookieName}.`;
|
|
@@ -50,7 +51,7 @@ function readExistingChunks(cookieName, ctx) {
|
|
|
50
51
|
* Split a cookie value into chunks if needed
|
|
51
52
|
*/
|
|
52
53
|
function chunkCookie(storeName, cookie, chunks, logger) {
|
|
53
|
-
const chunkSize = getMaxCookieValueSize(`${cookie.name}
|
|
54
|
+
const chunkSize = getMaxCookieValueSize(`${cookie.name}.99`, cookie.attributes);
|
|
54
55
|
const chunkCount = chunkSize > 0 ? Math.ceil(cookie.value.length / chunkSize) : Infinity;
|
|
55
56
|
if (chunkCount <= 1) {
|
|
56
57
|
chunks[cookie.name] = cookie.value;
|
package/dist/crypto/buffer.d.mts
CHANGED
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Compare two buffers in constant time.
|
|
4
4
|
*/
|
|
5
|
-
declare function constantTimeEqual(a: ArrayBuffer | Uint8Array | string, b: ArrayBuffer | Uint8Array | string): boolean;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { constantTimeEqual };
|
|
5
|
+
export declare function constantTimeEqual(a: ArrayBuffer | Uint8Array | string, b: ArrayBuffer | Uint8Array | string): boolean;
|
|
6
|
+
//#endregion
|