better-auth 1.7.11 → 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 +14 -53
- 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/session.mjs +1 -1
- 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/callback.mjs +68 -0
- 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/adapter.mjs +14 -3
- package/dist/plugins/jwt/client.d.mts +2 -3
- package/dist/plugins/jwt/cookie-cache.mjs +3 -8
- package/dist/plugins/jwt/index.d.mts +11 -14
- package/dist/plugins/jwt/index.mjs +3 -3
- package/dist/plugins/jwt/schema.d.mts +2 -3
- package/dist/plugins/jwt/sign.d.mts +9 -8
- package/dist/plugins/jwt/sign.mjs +6 -5
- 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/jwt/verify.mjs +10 -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 +24 -48
- 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 +13 -13
|
@@ -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 };
|
|
@@ -41,14 +41,15 @@ function createAuthClient(options) {
|
|
|
41
41
|
}
|
|
42
42
|
return resolvedHooks.useSession();
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
const routes = {
|
|
45
45
|
...pluginsActions,
|
|
46
46
|
...resolvedHooks,
|
|
47
47
|
hydrateSession,
|
|
48
48
|
useSession,
|
|
49
49
|
$fetch,
|
|
50
50
|
$store
|
|
51
|
-
}
|
|
51
|
+
};
|
|
52
|
+
return createDynamicPathProxy(routes, $fetch, pluginPathMethods, pluginsAtoms, atomListeners);
|
|
52
53
|
}
|
|
53
54
|
//#endregion
|
|
54
55
|
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) {
|
|
@@ -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
|
package/dist/crypto/index.d.mts
CHANGED
|
@@ -3,30 +3,23 @@ import { signJWT, symmetricDecodeJWT, symmetricEncodeJWT, verifyJWT } from "./jw
|
|
|
3
3
|
import { hashPassword, verifyPassword } from "./password.mjs";
|
|
4
4
|
import { generateRandomString } from "./random.mjs";
|
|
5
5
|
import { SecretConfig } from "@better-auth/core";
|
|
6
|
-
|
|
7
6
|
//#region src/crypto/index.d.ts
|
|
8
|
-
declare function parseEnvelope(data: string): {
|
|
7
|
+
export declare function parseEnvelope(data: string): {
|
|
9
8
|
version: number;
|
|
10
9
|
ciphertext: string;
|
|
11
10
|
} | null;
|
|
12
|
-
declare function formatEnvelope(version: number, ciphertext: string): string;
|
|
13
|
-
type SymmetricEncryptOptions = {
|
|
11
|
+
export declare function formatEnvelope(version: number, ciphertext: string): string;
|
|
12
|
+
export type SymmetricEncryptOptions = {
|
|
14
13
|
key: string | SecretConfig;
|
|
15
14
|
data: string;
|
|
16
15
|
};
|
|
17
|
-
declare const symmetricEncrypt: ({
|
|
18
|
-
|
|
19
|
-
data
|
|
20
|
-
}: SymmetricEncryptOptions) => Promise<string>;
|
|
21
|
-
type SymmetricDecryptOptions = {
|
|
16
|
+
export declare const symmetricEncrypt: ({ key, data }: SymmetricEncryptOptions) => Promise<string>;
|
|
17
|
+
export type SymmetricDecryptOptions = {
|
|
22
18
|
key: string | SecretConfig;
|
|
23
19
|
data: string;
|
|
24
20
|
};
|
|
25
|
-
declare const symmetricDecrypt: ({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}: SymmetricDecryptOptions) => Promise<string>;
|
|
29
|
-
declare const getCryptoKey: (secret: string | BufferSource) => Promise<CryptoKey>;
|
|
30
|
-
declare const makeSignature: (value: string, secret: string | BufferSource) => Promise<string>;
|
|
21
|
+
export declare const symmetricDecrypt: ({ key, data }: SymmetricDecryptOptions) => Promise<string>;
|
|
22
|
+
export declare const getCryptoKey: (secret: string | BufferSource) => Promise<CryptoKey>;
|
|
23
|
+
export declare const makeSignature: (value: string, secret: string | BufferSource) => Promise<string>;
|
|
31
24
|
//#endregion
|
|
32
|
-
export { type SecretConfig,
|
|
25
|
+
export { type SecretConfig, constantTimeEqual, generateRandomString, hashPassword, signJWT, symmetricDecodeJWT, symmetricEncodeJWT, verifyJWT, verifyPassword };
|
package/dist/crypto/index.mjs
CHANGED
|
@@ -30,7 +30,8 @@ function formatEnvelope(version, ciphertext) {
|
|
|
30
30
|
async function rawEncrypt(secret, data) {
|
|
31
31
|
const keyAsBytes = await createHash("SHA-256").digest(secret);
|
|
32
32
|
const dataAsBytes = utf8ToBytes(data);
|
|
33
|
-
|
|
33
|
+
const chacha = managedNonce(xchacha20poly1305)(new Uint8Array(keyAsBytes));
|
|
34
|
+
return bytesToHex(chacha.encrypt(dataAsBytes));
|
|
34
35
|
}
|
|
35
36
|
async function rawDecrypt(secret, hex) {
|
|
36
37
|
const keyAsBytes = await createHash("SHA-256").digest(secret);
|
package/dist/crypto/jwt.d.mts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { SecretConfig } from "./index.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/crypto/jwt.d.ts
|
|
4
|
-
declare function signJWT(payload: any, secret: string, expiresIn?: number): Promise<string>;
|
|
5
|
-
declare function verifyJWT<T = any>(token: string, secret: string): Promise<T | null>;
|
|
6
|
-
declare function symmetricEncodeJWT<T extends Record<string, any>>(payload: T, secret: string | SecretConfig, salt: string, expiresIn?: number): Promise<string>;
|
|
7
|
-
declare function symmetricDecodeJWT<T = any>(token: string, secret: string | SecretConfig, salt: string): Promise<T | null>;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { signJWT, symmetricDecodeJWT, symmetricEncodeJWT, verifyJWT };
|
|
3
|
+
export declare function signJWT(payload: any, secret: string, expiresIn?: number): Promise<string>;
|
|
4
|
+
export declare function verifyJWT<T = any>(token: string, secret: string): Promise<T | null>;
|
|
5
|
+
export declare function symmetricEncodeJWT<T extends Record<string, any>>(payload: T, secret: string | SecretConfig, salt: string, expiresIn?: number): Promise<string>;
|
|
6
|
+
export declare function symmetricDecodeJWT<T = any>(token: string, secret: string | SecretConfig, salt: string): Promise<T | null>;
|
|
7
|
+
//#endregion
|
package/dist/crypto/jwt.mjs
CHANGED
|
@@ -129,7 +129,8 @@ async function symmetricDecodeJWT(token, secret, salt) {
|
|
|
129
129
|
if (secrets.length <= 1) return null;
|
|
130
130
|
for (let i = 1; i < secrets.length; i++) try {
|
|
131
131
|
const s = secrets[i];
|
|
132
|
-
const
|
|
132
|
+
const encryptionSecret = deriveEncryptionSecret(s.value, salt);
|
|
133
|
+
const { payload } = await jwtDecrypt(token, encryptionSecret, jwtDecryptOpts);
|
|
133
134
|
return payload;
|
|
134
135
|
} catch {
|
|
135
136
|
continue;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { hashPassword } from "@better-auth/utils/password";
|
|
2
|
-
|
|
3
2
|
//#region src/crypto/password.d.ts
|
|
4
3
|
declare const hashPassword$1: typeof hashPassword;
|
|
5
|
-
declare const verifyPassword$1: ({
|
|
6
|
-
hash,
|
|
7
|
-
password
|
|
8
|
-
}: {
|
|
4
|
+
declare const verifyPassword$1: ({ hash, password }: {
|
|
9
5
|
hash: string;
|
|
10
6
|
password: string;
|
|
11
7
|
}) => Promise<boolean>;
|
package/dist/crypto/random.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
//#region src/crypto/random.d.ts
|
|
2
|
-
declare const generateRandomString: <SubA extends "a-z" | "A-Z" | "0-9" | "-_">(length: number, ...alphabets: SubA[]) => string;
|
|
3
|
-
//#endregion
|
|
4
|
-
export { generateRandomString };
|
|
2
|
+
export declare const generateRandomString: <SubA extends "a-z" | "A-Z" | "0-9" | "-_">(length: number, ...alphabets: SubA[]) => string;
|
|
3
|
+
//#endregion
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { BetterAuthOptions } from "@better-auth/core";
|
|
2
2
|
import { DBAdapter } from "@better-auth/core/db/adapter";
|
|
3
|
-
|
|
4
3
|
//#region src/db/adapter-base.d.ts
|
|
5
|
-
declare function getBaseAdapter(options: BetterAuthOptions, handleDirectDatabase: (options: BetterAuthOptions) => Promise<DBAdapter<BetterAuthOptions>>): Promise<DBAdapter<BetterAuthOptions>>;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { getBaseAdapter };
|
|
4
|
+
export declare function getBaseAdapter(options: BetterAuthOptions, handleDirectDatabase: (options: BetterAuthOptions) => Promise<DBAdapter<BetterAuthOptions>>): Promise<DBAdapter<BetterAuthOptions>>;
|
|
5
|
+
//#endregion
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { BetterAuthOptions } from "@better-auth/core";
|
|
2
2
|
import { DBAdapter } from "@better-auth/core/db/adapter";
|
|
3
|
-
|
|
4
3
|
//#region src/db/adapter-kysely.d.ts
|
|
5
|
-
declare function getAdapter(options: BetterAuthOptions): Promise<DBAdapter<BetterAuthOptions>>;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { getAdapter };
|
|
4
|
+
export declare function getAdapter(options: BetterAuthOptions): Promise<DBAdapter<BetterAuthOptions>>;
|
|
5
|
+
//#endregion
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { DBFieldAttribute } from "@better-auth/core/db";
|
|
2
|
-
|
|
3
2
|
//#region src/db/field-converter.d.ts
|
|
4
|
-
declare function convertToDB<T extends Record<string, any>>(fields: Record<string, DBFieldAttribute>, values: T): T;
|
|
5
|
-
declare function convertFromDB<T extends Record<string, any>>(fields: Record<string, DBFieldAttribute>, values: T | null): T | null;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { convertFromDB, convertToDB };
|
|
3
|
+
export declare function convertToDB<T extends Record<string, any>>(fields: Record<string, DBFieldAttribute>, values: T): T;
|
|
4
|
+
export declare function convertFromDB<T extends Record<string, any>>(fields: Record<string, DBFieldAttribute>, values: T | null): T | null;
|
|
5
|
+
//#endregion
|