@better-auth/core 1.6.23 → 1.6.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/dist/api/index.d.mts +28 -28
  2. package/dist/async_hooks/index.d.mts +0 -1
  3. package/dist/async_hooks/pure.index.d.mts +0 -1
  4. package/dist/context/endpoint-context.d.mts +1 -1
  5. package/dist/context/global.d.mts +0 -1
  6. package/dist/context/global.mjs +1 -1
  7. package/dist/context/request-state.d.mts +0 -1
  8. package/dist/context/request-state.mjs +8 -5
  9. package/dist/context/transaction.d.mts +1 -1
  10. package/dist/db/adapter/factory.d.mts +3 -5
  11. package/dist/db/adapter/factory.mjs +1 -1
  12. package/dist/db/adapter/get-default-field-name.d.mts +2 -9
  13. package/dist/db/adapter/get-default-model-name.d.mts +1 -5
  14. package/dist/db/adapter/get-default-model-name.mjs +6 -5
  15. package/dist/db/adapter/get-field-attributes.d.mts +4 -11
  16. package/dist/db/adapter/get-field-name.d.mts +2 -9
  17. package/dist/db/adapter/get-id-field.d.mts +4 -12
  18. package/dist/db/adapter/get-model-name.d.mts +1 -5
  19. package/dist/db/adapter/index.d.mts +7 -32
  20. package/dist/db/adapter/types.d.mts +5 -17
  21. package/dist/db/adapter/utils.d.mts +0 -1
  22. package/dist/db/get-tables.d.mts +1 -0
  23. package/dist/db/get-tables.mjs +2 -2
  24. package/dist/db/plugin.d.mts +1 -2
  25. package/dist/db/schema/account.d.mts +1 -1
  26. package/dist/db/schema/account.mjs +12 -0
  27. package/dist/db/schema/rate-limit.d.mts +1 -1
  28. package/dist/db/schema/rate-limit.mjs +9 -0
  29. package/dist/db/schema/session.d.mts +1 -1
  30. package/dist/db/schema/shared.d.mts +0 -1
  31. package/dist/db/schema/user.d.mts +1 -1
  32. package/dist/db/schema/verification.d.mts +1 -1
  33. package/dist/db/type.d.mts +5 -8
  34. package/dist/env/logger.d.mts +25 -25
  35. package/dist/error/codes.d.mts +0 -1
  36. package/dist/error/index.d.mts +0 -1
  37. package/dist/index.d.mts +1 -1
  38. package/dist/instrumentation/attributes.d.mts +0 -1
  39. package/dist/instrumentation/pure.index.d.mts +0 -1
  40. package/dist/instrumentation/tracer.mjs +1 -1
  41. package/dist/oauth2/client-credentials-token.d.mts +4 -20
  42. package/dist/oauth2/client-credentials-token.mjs +1 -4
  43. package/dist/oauth2/create-authorization-url.d.mts +3 -20
  44. package/dist/oauth2/oauth-provider.d.mts +9 -3
  45. package/dist/oauth2/refresh-access-token.d.mts +4 -22
  46. package/dist/oauth2/refresh-access-token.mjs +2 -8
  47. package/dist/oauth2/reject-redirects.mjs +1 -1
  48. package/dist/oauth2/utils.d.mts +0 -1
  49. package/dist/oauth2/utils.mjs +1 -2
  50. package/dist/oauth2/validate-authorization-code.d.mts +6 -37
  51. package/dist/oauth2/verify.d.mts +12 -10
  52. package/dist/oauth2/verify.mjs +2 -2
  53. package/dist/social-providers/apple.d.mts +7 -28
  54. package/dist/social-providers/apple.mjs +2 -2
  55. package/dist/social-providers/atlassian.d.mts +3 -11
  56. package/dist/social-providers/cognito.d.mts +6 -12
  57. package/dist/social-providers/cognito.mjs +2 -2
  58. package/dist/social-providers/discord.d.mts +3 -9
  59. package/dist/social-providers/dropbox.d.mts +3 -11
  60. package/dist/social-providers/facebook.d.mts +6 -11
  61. package/dist/social-providers/facebook.mjs +2 -2
  62. package/dist/social-providers/figma.d.mts +3 -11
  63. package/dist/social-providers/github.d.mts +3 -12
  64. package/dist/social-providers/gitlab.d.mts +3 -12
  65. package/dist/social-providers/google.d.mts +7 -20
  66. package/dist/social-providers/google.mjs +2 -2
  67. package/dist/social-providers/huggingface.d.mts +3 -11
  68. package/dist/social-providers/index.d.mts +78 -362
  69. package/dist/social-providers/kakao.d.mts +3 -9
  70. package/dist/social-providers/kick.d.mts +3 -11
  71. package/dist/social-providers/line.d.mts +6 -13
  72. package/dist/social-providers/line.mjs +2 -2
  73. package/dist/social-providers/linear.d.mts +3 -10
  74. package/dist/social-providers/linkedin.d.mts +3 -10
  75. package/dist/social-providers/microsoft-entra-id.d.mts +5 -6
  76. package/dist/social-providers/microsoft-entra-id.mjs +4 -3
  77. package/dist/social-providers/naver.d.mts +22 -18
  78. package/dist/social-providers/notion.d.mts +3 -10
  79. package/dist/social-providers/paybin.d.mts +3 -12
  80. package/dist/social-providers/paypal.d.mts +6 -10
  81. package/dist/social-providers/paypal.mjs +2 -2
  82. package/dist/social-providers/polar.d.mts +3 -11
  83. package/dist/social-providers/railway.d.mts +3 -11
  84. package/dist/social-providers/reddit.d.mts +3 -9
  85. package/dist/social-providers/roblox.d.mts +3 -9
  86. package/dist/social-providers/salesforce.d.mts +3 -11
  87. package/dist/social-providers/slack.d.mts +3 -9
  88. package/dist/social-providers/spotify.d.mts +3 -11
  89. package/dist/social-providers/tiktok.d.mts +5 -10
  90. package/dist/social-providers/twitch.d.mts +3 -9
  91. package/dist/social-providers/twitter.d.mts +26 -17
  92. package/dist/social-providers/vercel.d.mts +3 -11
  93. package/dist/social-providers/vk.d.mts +3 -12
  94. package/dist/social-providers/vk.mjs +4 -5
  95. package/dist/social-providers/wechat.d.mts +3 -8
  96. package/dist/social-providers/zoom.d.mts +5 -14
  97. package/dist/types/context.d.mts +2 -1
  98. package/dist/types/cookie.d.mts +0 -1
  99. package/dist/types/helper.d.mts +1 -1
  100. package/dist/types/index.d.mts +1 -1
  101. package/dist/types/init-options.d.mts +10 -7
  102. package/dist/types/plugin-client.d.mts +1 -3
  103. package/dist/types/plugin.d.mts +2 -2
  104. package/dist/utils/async.d.mts +0 -1
  105. package/dist/utils/db.d.mts +1 -0
  106. package/dist/utils/deprecate.d.mts +0 -1
  107. package/dist/utils/error-codes.d.mts +2 -2
  108. package/dist/utils/host.d.mts +27 -1
  109. package/dist/utils/host.mjs +1 -1
  110. package/dist/utils/ip.d.mts +1 -0
  111. package/dist/utils/ip.mjs +1 -1
  112. package/dist/utils/is-api-error.d.mts +0 -1
  113. package/dist/utils/redirect-uri.d.mts +0 -1
  114. package/package.json +2 -2
  115. package/src/context/request-state.ts +26 -6
  116. package/src/db/adapter/get-default-model-name.ts +23 -14
  117. package/src/db/get-tables.ts +17 -2
  118. package/src/oauth2/oauth-provider.ts +20 -4
  119. package/src/social-providers/apple.ts +7 -2
  120. package/src/social-providers/cognito.ts +7 -2
  121. package/src/social-providers/facebook.ts +7 -2
  122. package/src/social-providers/google.ts +7 -2
  123. package/src/social-providers/line.ts +7 -2
  124. package/src/social-providers/microsoft-entra-id.ts +7 -2
  125. package/src/social-providers/paypal.ts +7 -2
@@ -1,8 +1,8 @@
1
1
  import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
2
2
  import { Prettify } from "../../types/helper.mjs";
3
3
  import { BetterAuthOptions } from "../../types/init-options.mjs";
4
+ import "../../types/index.mjs";
4
5
  import * as z from "zod";
5
-
6
6
  //#region src/db/schema/user.d.ts
7
7
  declare const userSchema: z.ZodObject<{
8
8
  id: z.ZodString;
@@ -1,8 +1,8 @@
1
1
  import { InferDBFieldsFromOptions, InferDBFieldsFromPlugins } from "../type.mjs";
2
2
  import { Prettify } from "../../types/helper.mjs";
3
3
  import { BetterAuthOptions } from "../../types/init-options.mjs";
4
+ import "../../types/index.mjs";
4
5
  import * as z from "zod";
5
-
6
6
  //#region src/db/schema/verification.d.ts
7
7
  declare const verificationSchema: z.ZodObject<{
8
8
  id: z.ZodString;
@@ -1,15 +1,15 @@
1
1
  import { Awaitable, LiteralString, UnionToIntersection } from "../types/helper.mjs";
2
2
  import { BetterAuthOptions } from "../types/init-options.mjs";
3
+ import "../types/index.mjs";
3
4
  import { StandardSchemaV1 } from "@standard-schema/spec";
4
-
5
5
  //#region src/db/type.d.ts
6
6
  type BaseModelNames = "user" | "account" | "session" | "verification";
7
7
  type ModelNames<T extends string = LiteralString> = BaseModelNames | T | "rate-limit";
8
8
  type InferDBValueType<T extends DBFieldType> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "date" ? Date : T extends "json" ? Record<string, any> : T extends `${infer U}[]` ? U extends "string" ? string[] : number[] : T extends Array<any> ? T[number] : never;
9
9
  type InferDBFieldOutput<T extends DBFieldAttribute> = T["returned"] extends false ? never : T["required"] extends false ? InferDBValueType<T["type"]> | undefined | null : InferDBValueType<T["type"]>;
10
10
  type InferDBFieldInput<T extends DBFieldAttribute> = InferDBValueType<T["type"]>;
11
- type InferDBFieldsInput<Field> = Field extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Field[key]["required"] extends false ? never : Field[key]["defaultValue"] extends string | number | boolean | Date ? never : Field[key]["input"] extends false ? never : key]: InferDBFieldInput<Field[key]> } & { [key in Key as Field[key]["input"] extends false ? never : key]?: InferDBFieldInput<Field[key]> | undefined | null } : {};
12
- type InferDBFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferDBFieldOutput<Fields[key]> } & { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? never : key : never]?: InferDBFieldOutput<Fields[key]> | null } : never;
11
+ type InferDBFieldsInput<Field> = Field extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Field[key]["required"] extends false ? never : Field[key]["defaultValue"] extends string | number | boolean | Date ? never : Field[key]["input"] extends false ? never : key]: InferDBFieldInput<Field[key]>; } & { [key in Key as Field[key]["input"] extends false ? never : key]?: InferDBFieldInput<Field[key]> | undefined | null; } : {};
12
+ type InferDBFieldsOutput<Fields extends Record<string, DBFieldAttribute>> = Fields extends Record<infer Key, DBFieldAttribute> ? { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? key : never : key]: InferDBFieldOutput<Fields[key]>; } & { [key in Key as Fields[key]["returned"] extends false ? never : Fields[key]["required"] extends false ? Fields[key]["defaultValue"] extends boolean | string | number | Date ? never : key : never]?: InferDBFieldOutput<Fields[key]> | null; } : never;
13
13
  type InferDBFieldsFromOptionsInput<DBOptions extends BetterAuthOptions["session"] | BetterAuthOptions["user"] | BetterAuthOptions["verification"] | BetterAuthOptions["account"] | BetterAuthOptions["rateLimit"]> = DBOptions extends {
14
14
  additionalFields: Record<string, DBFieldAttribute>;
15
15
  } ? InferDBFieldsInput<DBOptions["additionalFields"]> : {};
@@ -19,12 +19,12 @@ type InferDBFieldsFromOptions<DBOptions extends BetterAuthOptions["session"] | B
19
19
  type InferDBFieldsFromPluginsInput<ModelName extends string, Plugins extends unknown[] | undefined> = Plugins extends [] ? {} : Plugins extends [infer P, ...infer Rest] ? P extends {
20
20
  schema: { [key in ModelName]: {
21
21
  fields: infer Fields;
22
- } };
22
+ }; };
23
23
  } ? Fields extends Record<string, DBFieldAttribute> ? UnionToIntersection<InferDBFieldsInput<Fields> & InferDBFieldsFromPluginsInput<ModelName, Rest>> : InferDBFieldsFromPluginsInput<ModelName, Rest> : InferDBFieldsFromPluginsInput<ModelName, Rest> : {};
24
24
  type InferDBFieldsFromPlugins<ModelName extends string, Plugins extends unknown[] | undefined> = Plugins extends [] ? {} : Plugins extends [infer P, ...infer Rest] ? P extends {
25
25
  schema: { [key in ModelName]: {
26
26
  fields: infer Fields;
27
- } };
27
+ }; };
28
28
  } ? Fields extends Record<string, DBFieldAttribute> ? UnionToIntersection<InferDBFieldsOutput<Fields> & InferDBFieldsFromPlugins<ModelName, Rest>> : InferDBFieldsFromPlugins<ModelName, Rest> : InferDBFieldsFromPlugins<ModelName, Rest> : {};
29
29
  type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
30
30
  type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[] | (Record<string, unknown> | unknown[]);
@@ -172,17 +172,14 @@ interface SecondaryStorage {
172
172
  /**
173
173
  * Key to store
174
174
  */
175
-
176
175
  key: string,
177
176
  /**
178
177
  * Value to store
179
178
  */
180
-
181
179
  value: string,
182
180
  /**
183
181
  * Time to live in seconds
184
182
  */
185
-
186
183
  ttl?: number | undefined) => Awaitable<void | null | unknown>;
187
184
  /**
188
185
  *
@@ -1,32 +1,32 @@
1
1
  //#region src/env/logger.d.ts
2
2
  declare const TTY_COLORS: {
3
- readonly reset: "\u001B[0m";
4
- readonly bright: "\u001B[1m";
5
- readonly dim: "\u001B[2m";
6
- readonly undim: "\u001B[22m";
7
- readonly underscore: "\u001B[4m";
8
- readonly blink: "\u001B[5m";
9
- readonly reverse: "\u001B[7m";
10
- readonly hidden: "\u001B[8m";
3
+ readonly reset: "";
4
+ readonly bright: "";
5
+ readonly dim: "";
6
+ readonly undim: "";
7
+ readonly underscore: "";
8
+ readonly blink: "";
9
+ readonly reverse: "";
10
+ readonly hidden: "";
11
11
  readonly fg: {
12
- readonly black: "\u001B[30m";
13
- readonly red: "\u001B[31m";
14
- readonly green: "\u001B[32m";
15
- readonly yellow: "\u001B[33m";
16
- readonly blue: "\u001B[34m";
17
- readonly magenta: "\u001B[35m";
18
- readonly cyan: "\u001B[36m";
19
- readonly white: "\u001B[37m";
12
+ readonly black: "";
13
+ readonly red: "";
14
+ readonly green: "";
15
+ readonly yellow: "";
16
+ readonly blue: "";
17
+ readonly magenta: "";
18
+ readonly cyan: "";
19
+ readonly white: "";
20
20
  };
21
21
  readonly bg: {
22
- readonly black: "\u001B[40m";
23
- readonly red: "\u001B[41m";
24
- readonly green: "\u001B[42m";
25
- readonly yellow: "\u001B[43m";
26
- readonly blue: "\u001B[44m";
27
- readonly magenta: "\u001B[45m";
28
- readonly cyan: "\u001B[46m";
29
- readonly white: "\u001B[47m";
22
+ readonly black: "";
23
+ readonly red: "";
24
+ readonly green: "";
25
+ readonly yellow: "";
26
+ readonly blue: "";
27
+ readonly magenta: "";
28
+ readonly cyan: "";
29
+ readonly white: "";
30
30
  };
31
31
  };
32
32
  type LogLevel = "debug" | "info" | "success" | "warn" | "error";
@@ -39,7 +39,7 @@ interface Logger {
39
39
  log?: ((level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void) | undefined;
40
40
  }
41
41
  type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [LogLevel, ...infer Rest] ? Rest : never;
42
- type InternalLogger = { [K in LogLevel]: (...params: LogHandlerParams) => void } & {
42
+ type InternalLogger = { [K in LogLevel]: (...params: LogHandlerParams) => void; } & {
43
43
  get level(): LogLevel;
44
44
  };
45
45
  declare const createLogger: (options?: Logger | undefined) => InternalLogger;
@@ -1,5 +1,4 @@
1
1
  import { RawError } from "../utils/error-codes.mjs";
2
-
3
2
  //#region src/error/codes.d.ts
4
3
  declare module "@better-auth/core" {
5
4
  interface BetterAuthPluginRegistry<AuthOptions, Options> {
@@ -1,6 +1,5 @@
1
1
  import { APIErrorCode, BASE_ERROR_CODES } from "./codes.mjs";
2
2
  import { APIError as APIError$1 } from "better-call/error";
3
-
4
3
  //#region src/error/index.d.ts
5
4
  declare class BetterAuthError extends Error {
6
5
  constructor(message: string, options?: {
package/dist/index.d.mts CHANGED
@@ -6,4 +6,4 @@ import { SecretConfig } from "./types/secret.mjs";
6
6
  import { AuthContext, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, GenericEndpointContext, InfoContext, InternalAdapter, PluginContext } from "./types/context.mjs";
7
7
  import { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore } from "./types/plugin-client.mjs";
8
8
  import { StandardSchemaV1 } from "./types/index.mjs";
9
- export { AuthContext, Awaitable, AwaitableFunction, BaseURLConfig, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookie, BetterAuthCookies, BetterAuthDBOptions, BetterAuthOptions, BetterAuthPlugin, BetterAuthPluginErrorCodePart, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, ClientAtomListener, ClientFetchOption, ClientStore, DynamicBaseURLConfig, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InfoContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, SecretConfig, StandardSchemaV1, StoreIdentifierOption, UnionToIntersection };
9
+ export type { AuthContext, Awaitable, AwaitableFunction, BaseURLConfig, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookie, BetterAuthCookies, BetterAuthDBOptions, BetterAuthOptions, BetterAuthPlugin, BetterAuthPluginErrorCodePart, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, ClientAtomListener, ClientFetchOption, ClientStore, DynamicBaseURLConfig, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InfoContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, SecretConfig, StandardSchemaV1, StoreIdentifierOption, UnionToIntersection };
@@ -1,5 +1,4 @@
1
1
  import { ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE } from "@opentelemetry/semantic-conventions";
2
-
3
2
  //#region src/instrumentation/attributes.d.ts
4
3
  /** Operation identifier (e.g. getSession, signUpWithEmailAndPassword). Uses endpoint operationId when set, otherwise the endpoint key. */
5
4
  declare const ATTR_OPERATION_ID: "better_auth.operation_id";
@@ -1,5 +1,4 @@
1
1
  import { ATTR_CONTEXT, ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID } from "./attributes.mjs";
2
-
3
2
  //#region src/instrumentation/pure.index.d.ts
4
3
  declare function withSpan<T>(name: string, attributes: Record<string, string | number | boolean>, fn: () => T): T;
5
4
  declare function withSpan<T>(name: string, attributes: Record<string, string | number | boolean>, fn: () => Promise<T>): Promise<T>;
@@ -2,7 +2,7 @@ import { ATTR_HTTP_RESPONSE_STATUS_CODE } from "./attributes.mjs";
2
2
  import { getOpenTelemetryAPI } from "./api.mjs";
3
3
  //#region src/instrumentation/tracer.ts
4
4
  const INSTRUMENTATION_SCOPE = "better-auth";
5
- const INSTRUMENTATION_VERSION = "1.6.23";
5
+ const INSTRUMENTATION_VERSION = "1.6.24";
6
6
  /**
7
7
  * Better-auth uses `throw ctx.redirect(url)` for flow control (e.g. OAuth
8
8
  * callbacks). These are APIErrors with 3xx status codes and should not be
@@ -1,13 +1,8 @@
1
1
  import { AwaitableFunction } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
2
3
  import { OAuth2Tokens, ProviderOptions } from "./oauth-provider.mjs";
3
-
4
4
  //#region src/oauth2/client-credentials-token.d.ts
5
- declare function clientCredentialsTokenRequest({
6
- options,
7
- scope,
8
- authentication,
9
- resource
10
- }: {
5
+ declare function clientCredentialsTokenRequest({ options, scope, authentication, resource }: {
11
6
  options: AwaitableFunction<ProviderOptions & {
12
7
  clientSecret: string;
13
8
  }>;
@@ -21,12 +16,7 @@ declare function clientCredentialsTokenRequest({
21
16
  /**
22
17
  * @deprecated use async'd clientCredentialsTokenRequest instead
23
18
  */
24
- declare function createClientCredentialsTokenRequest({
25
- options,
26
- scope,
27
- authentication,
28
- resource
29
- }: {
19
+ declare function createClientCredentialsTokenRequest({ options, scope, authentication, resource }: {
30
20
  options: ProviderOptions & {
31
21
  clientSecret: string;
32
22
  };
@@ -37,13 +27,7 @@ declare function createClientCredentialsTokenRequest({
37
27
  body: URLSearchParams;
38
28
  headers: Record<string, any>;
39
29
  };
40
- declare function clientCredentialsToken({
41
- options,
42
- tokenEndpoint,
43
- scope,
44
- authentication,
45
- resource
46
- }: {
30
+ declare function clientCredentialsToken({ options, tokenEndpoint, scope, authentication, resource }: {
47
31
  options: AwaitableFunction<ProviderOptions & {
48
32
  clientSecret: string;
49
33
  }>;
@@ -54,10 +54,7 @@ async function clientCredentialsToken({ options, tokenEndpoint, scope, authentic
54
54
  tokenType: data.token_type,
55
55
  scopes: data.scope?.split(" ")
56
56
  };
57
- if (data.expires_in) {
58
- const now = /* @__PURE__ */ new Date();
59
- tokens.accessTokenExpiresAt = new Date(now.getTime() + data.expires_in * 1e3);
60
- }
57
+ if (data.expires_in) tokens.accessTokenExpiresAt = new Date((/* @__PURE__ */ new Date()).getTime() + data.expires_in * 1e3);
61
58
  return tokens;
62
59
  }
63
60
  //#endregion
@@ -1,26 +1,9 @@
1
1
  import { AwaitableFunction } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
2
3
  import { ProviderOptions } from "./oauth-provider.mjs";
4
+ import "./index.mjs";
3
5
  //#region src/oauth2/create-authorization-url.d.ts
4
- declare function createAuthorizationURL({
5
- id,
6
- options,
7
- authorizationEndpoint,
8
- state,
9
- codeVerifier,
10
- scopes,
11
- claims,
12
- redirectURI,
13
- duration,
14
- prompt,
15
- accessType,
16
- responseType,
17
- display,
18
- loginHint,
19
- hd,
20
- responseMode,
21
- additionalParams,
22
- scopeJoiner
23
- }: {
6
+ declare function createAuthorizationURL({ id, options, authorizationEndpoint, state, codeVerifier, scopes, claims, redirectURI, duration, prompt, accessType, responseType, display, loginHint, hd, responseMode, additionalParams, scopeJoiner }: {
24
7
  id: string;
25
8
  options: AwaitableFunction<ProviderOptions>;
26
9
  redirectURI: string;
@@ -1,4 +1,6 @@
1
1
  import { Awaitable, LiteralString } from "../types/helper.mjs";
2
+ import { GenericEndpointContext } from "../types/context.mjs";
3
+ import "../types/index.mjs";
2
4
  //#region src/oauth2/oauth-provider.d.ts
3
5
  interface OAuth2Tokens {
4
6
  tokenType?: string | undefined;
@@ -63,9 +65,10 @@ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O e
63
65
  * Verify the id token
64
66
  * @param token - The id token
65
67
  * @param nonce - The nonce
68
+ * @param ctx - Request endpoint context (headers via `ctx.headers`)
66
69
  * @returns True if the id token is valid, false otherwise
67
70
  */
68
- verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
71
+ verifyIdToken?: ((token: string, nonce?: string, ctx?: GenericEndpointContext) => Promise<boolean>) | undefined;
69
72
  /**
70
73
  * Disable implicit sign up for new users. When set to true for the provider,
71
74
  * sign-in need to be called with with requestSignUp as true to create new users.
@@ -123,9 +126,12 @@ type ProviderOptions<Profile extends Record<string, any> = any> = {
123
126
  */
124
127
  disableIdTokenSignIn?: boolean | undefined;
125
128
  /**
126
- * verifyIdToken function to verify the id token
129
+ * Custom function to verify the id token.
130
+ * @param token - The id token
131
+ * @param nonce - The nonce
132
+ * @param ctx - Request endpoint context (headers via `ctx.headers`)
127
133
  */
128
- verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
134
+ verifyIdToken?: ((token: string, nonce?: string, ctx?: GenericEndpointContext) => Promise<boolean>) | undefined;
129
135
  /**
130
136
  * Custom function to get user info from the provider
131
137
  */
@@ -1,14 +1,8 @@
1
1
  import { AwaitableFunction } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
2
3
  import { OAuth2Tokens, ProviderOptions } from "./oauth-provider.mjs";
3
-
4
4
  //#region src/oauth2/refresh-access-token.d.ts
5
- declare function refreshAccessTokenRequest({
6
- refreshToken,
7
- options,
8
- authentication,
9
- extraParams,
10
- resource
11
- }: {
5
+ declare function refreshAccessTokenRequest({ refreshToken, options, authentication, extraParams, resource }: {
12
6
  refreshToken: string;
13
7
  options: AwaitableFunction<Partial<ProviderOptions>>;
14
8
  authentication?: ("basic" | "post") | undefined;
@@ -21,13 +15,7 @@ declare function refreshAccessTokenRequest({
21
15
  /**
22
16
  * @deprecated use async'd refreshAccessTokenRequest instead
23
17
  */
24
- declare function createRefreshAccessTokenRequest({
25
- refreshToken,
26
- options,
27
- authentication,
28
- extraParams,
29
- resource
30
- }: {
18
+ declare function createRefreshAccessTokenRequest({ refreshToken, options, authentication, extraParams, resource }: {
31
19
  refreshToken: string;
32
20
  options: ProviderOptions;
33
21
  authentication?: ("basic" | "post") | undefined;
@@ -37,13 +25,7 @@ declare function createRefreshAccessTokenRequest({
37
25
  body: URLSearchParams;
38
26
  headers: Record<string, any>;
39
27
  };
40
- declare function refreshAccessToken({
41
- refreshToken,
42
- options,
43
- tokenEndpoint,
44
- authentication,
45
- extraParams
46
- }: {
28
+ declare function refreshAccessToken({ refreshToken, options, tokenEndpoint, authentication, extraParams }: {
47
29
  refreshToken: string;
48
30
  options: Partial<ProviderOptions>;
49
31
  tokenEndpoint: string;
@@ -59,14 +59,8 @@ async function refreshAccessToken({ refreshToken, options, tokenEndpoint, authen
59
59
  scopes: data.scope?.split(" "),
60
60
  idToken: data.id_token
61
61
  };
62
- if (data.expires_in) {
63
- const now = /* @__PURE__ */ new Date();
64
- tokens.accessTokenExpiresAt = new Date(now.getTime() + data.expires_in * 1e3);
65
- }
66
- if (data.refresh_token_expires_in) {
67
- const now = /* @__PURE__ */ new Date();
68
- tokens.refreshTokenExpiresAt = new Date(now.getTime() + data.refresh_token_expires_in * 1e3);
69
- }
62
+ if (data.expires_in) tokens.accessTokenExpiresAt = new Date((/* @__PURE__ */ new Date()).getTime() + data.expires_in * 1e3);
63
+ if (data.refresh_token_expires_in) tokens.refreshTokenExpiresAt = new Date((/* @__PURE__ */ new Date()).getTime() + data.refresh_token_expires_in * 1e3);
70
64
  return tokens;
71
65
  }
72
66
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { BetterAuthError } from "../error/index.mjs";
2
2
  import { betterFetch } from "@better-fetch/fetch";
3
3
  //#region src/oauth2/reject-redirects.ts
4
- const HTTP_REDIRECT_STATUSES = new Set([
4
+ const HTTP_REDIRECT_STATUSES = /* @__PURE__ */ new Set([
5
5
  301,
6
6
  302,
7
7
  303,
@@ -1,5 +1,4 @@
1
1
  import { OAuth2Tokens } from "./oauth-provider.mjs";
2
-
3
2
  //#region src/oauth2/utils.d.ts
4
3
  declare function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens;
5
4
  /**
@@ -2,8 +2,7 @@ import { base64Url } from "@better-auth/utils/base64";
2
2
  //#region src/oauth2/utils.ts
3
3
  function getOAuth2Tokens(data) {
4
4
  const getDate = (seconds) => {
5
- const now = /* @__PURE__ */ new Date();
6
- return new Date(now.getTime() + seconds * 1e3);
5
+ return new Date((/* @__PURE__ */ new Date()).getTime() + seconds * 1e3);
7
6
  };
8
7
  return {
9
8
  tokenType: data.token_type,
@@ -1,19 +1,9 @@
1
1
  import { AwaitableFunction } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
2
3
  import { OAuth2Tokens, ProviderOptions } from "./oauth-provider.mjs";
3
- import * as jose from "jose";
4
-
4
+ import "./index.mjs";
5
5
  //#region src/oauth2/validate-authorization-code.d.ts
6
- declare function authorizationCodeRequest({
7
- code,
8
- codeVerifier,
9
- redirectURI,
10
- options,
11
- authentication,
12
- deviceId,
13
- headers,
14
- additionalParams,
15
- resource
16
- }: {
6
+ declare function authorizationCodeRequest({ code, codeVerifier, redirectURI, options, authentication, deviceId, headers, additionalParams, resource }: {
17
7
  code: string;
18
8
  redirectURI: string;
19
9
  options: AwaitableFunction<Partial<ProviderOptions>>;
@@ -30,17 +20,7 @@ declare function authorizationCodeRequest({
30
20
  /**
31
21
  * @deprecated use async'd authorizationCodeRequest instead
32
22
  */
33
- declare function createAuthorizationCodeRequest({
34
- code,
35
- codeVerifier,
36
- redirectURI,
37
- options,
38
- authentication,
39
- deviceId,
40
- headers,
41
- additionalParams,
42
- resource
43
- }: {
23
+ declare function createAuthorizationCodeRequest({ code, codeVerifier, redirectURI, options, authentication, deviceId, headers, additionalParams, resource }: {
44
24
  code: string;
45
25
  redirectURI: string;
46
26
  options: Partial<ProviderOptions>;
@@ -54,18 +34,7 @@ declare function createAuthorizationCodeRequest({
54
34
  body: URLSearchParams;
55
35
  headers: Record<string, any>;
56
36
  };
57
- declare function validateAuthorizationCode({
58
- code,
59
- codeVerifier,
60
- redirectURI,
61
- options,
62
- tokenEndpoint,
63
- authentication,
64
- deviceId,
65
- headers,
66
- additionalParams,
67
- resource
68
- }: {
37
+ declare function validateAuthorizationCode({ code, codeVerifier, redirectURI, options, tokenEndpoint, authentication, deviceId, headers, additionalParams, resource }: {
69
38
  code: string;
70
39
  redirectURI: string;
71
40
  options: AwaitableFunction<Partial<ProviderOptions>>;
@@ -80,6 +49,6 @@ declare function validateAuthorizationCode({
80
49
  declare function validateToken(token: string, jwksEndpoint: string, options?: {
81
50
  audience?: string | string[];
82
51
  issuer?: string | string[];
83
- }): Promise<jose.JWTVerifyResult<jose.JWTPayload> & jose.ResolvedKey>;
52
+ }): Promise<import("jose").JWTVerifyResult<import("jose").JWTPayload> & import("jose").ResolvedKey>;
84
53
  //#endregion
85
54
  export { authorizationCodeRequest, createAuthorizationCodeRequest, validateAuthorizationCode, validateToken };
@@ -1,8 +1,8 @@
1
1
  import { JSONWebKeySet, JWTPayload, JWTVerifyOptions } from "jose";
2
-
3
2
  //#region src/oauth2/verify.d.ts
4
3
  type JwksFetchOptions = {
5
- /** Jwks url or promise of a Jwks */jwksFetch: string | (() => Promise<JSONWebKeySet | undefined>);
4
+ /** Jwks url or promise of a Jwks */
5
+ jwksFetch: string | (() => Promise<JSONWebKeySet | undefined>);
6
6
  /**
7
7
  * Stable object to cache the result of a function `jwksFetch` under,
8
8
  * with the same TTL and kid-miss refetch rules as string sources.
@@ -10,9 +10,6 @@ type JwksFetchOptions = {
10
10
  */
11
11
  jwksCacheKey?: object;
12
12
  };
13
- /**
14
- * @internal
15
- */
16
13
  interface VerifyAccessTokenRemote {
17
14
  /** Full url of the introspect endpoint. Should end with `/oauth2/introspect` */
18
15
  introspectUrl: string;
@@ -47,7 +44,8 @@ interface VerifyAccessTokenRemote {
47
44
  * Can also be configured for remote verification.
48
45
  */
49
46
  declare function verifyJwsAccessToken(token: string, opts: JwksFetchOptions & {
50
- /** Verify options */verifyOptions: JWTVerifyOptions & Required<Pick<JWTVerifyOptions, "audience" | "issuer">>;
47
+ /** Verify options */
48
+ verifyOptions: JWTVerifyOptions & Required<Pick<JWTVerifyOptions, "audience" | "issuer">>;
51
49
  }): Promise<JWTPayload>;
52
50
  declare function getJwks(token: string, opts: JwksFetchOptions): Promise<JSONWebKeySet>;
53
51
  /**
@@ -56,10 +54,14 @@ declare function getJwks(token: string, opts: JwksFetchOptions): Promise<JSONWeb
56
54
  * Can also be configured for remote verification.
57
55
  */
58
56
  declare function verifyAccessToken(token: string, opts: {
59
- /** Verify options */verifyOptions: JWTVerifyOptions & Required<Pick<JWTVerifyOptions, "audience" | "issuer">>; /** Scopes to additionally verify. Token must include all but not exact. */
60
- scopes?: string[]; /** Required to verify access token locally */
61
- jwksUrl?: string; /** If provided, can verify a token remotely */
57
+ /** Verify options */
58
+ verifyOptions: JWTVerifyOptions & Required<Pick<JWTVerifyOptions, "audience" | "issuer">>;
59
+ /** Scopes to additionally verify. Token must include all but not exact. */
60
+ scopes?: string[];
61
+ /** Required to verify access token locally */
62
+ jwksUrl?: string;
63
+ /** If provided, can verify a token remotely */
62
64
  remoteVerify?: VerifyAccessTokenRemote;
63
65
  }): Promise<JWTPayload>;
64
66
  //#endregion
65
- export { getJwks, verifyAccessToken, verifyJwsAccessToken };
67
+ export { VerifyAccessTokenRemote, getJwks, verifyAccessToken, verifyJwsAccessToken };
@@ -3,7 +3,7 @@ import { fetchRefusingRedirects } from "./reject-redirects.mjs";
3
3
  import { APIError } from "better-call";
4
4
  import { UnsecuredJWT, createLocalJWKSet, decodeProtectedHeader, errors, jwtVerify } from "jose";
5
5
  //#region src/oauth2/verify.ts
6
- const joseInfrastructureErrorCodes = new Set([
6
+ const joseInfrastructureErrorCodes = /* @__PURE__ */ new Set([
7
7
  errors.JWKSTimeout.code,
8
8
  errors.JWKSInvalid.code,
9
9
  errors.JWKSMultipleMatchingKeys.code
@@ -199,4 +199,4 @@ async function verifyAccessToken(token, opts) {
199
199
  return payload;
200
200
  }
201
201
  //#endregion
202
- export { getJwks, verifyAccessToken, verifyJwsAccessToken };
202
+ export { getJwks, jwksCache, verifyAccessToken, verifyJwsAccessToken };
@@ -1,4 +1,7 @@
1
+ import { GenericEndpointContext } from "../types/context.mjs";
2
+ import "../types/index.mjs";
1
3
  import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
4
+ import "../oauth2/index.mjs";
2
5
  //#region src/social-providers/apple.d.ts
3
6
  interface AppleProfile {
4
7
  /**
@@ -67,11 +70,7 @@ interface AppleOptions extends ProviderOptions<AppleProfile> {
67
70
  declare const apple: (options: AppleOptions) => {
68
71
  id: "apple";
69
72
  name: string;
70
- createAuthorizationURL({
71
- state,
72
- scopes,
73
- redirectURI
74
- }: {
73
+ createAuthorizationURL({ state, scopes, redirectURI }: {
75
74
  state: string;
76
75
  codeVerifier: string;
77
76
  scopes?: string[] | undefined;
@@ -79,37 +78,17 @@ declare const apple: (options: AppleOptions) => {
79
78
  display?: string | undefined;
80
79
  loginHint?: string | undefined;
81
80
  }): Promise<URL>;
82
- validateAuthorizationCode: ({
83
- code,
84
- codeVerifier,
85
- redirectURI
86
- }: {
81
+ validateAuthorizationCode: ({ code, codeVerifier, redirectURI }: {
87
82
  code: string;
88
83
  redirectURI: string;
89
84
  codeVerifier?: string | undefined;
90
85
  deviceId?: string | undefined;
91
86
  }) => Promise<OAuth2Tokens>;
92
- verifyIdToken(token: string, nonce: string | undefined): Promise<boolean>;
87
+ verifyIdToken(token: string, nonce?: string, ctx?: GenericEndpointContext): Promise<boolean>;
93
88
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
94
89
  getUserInfo(token: OAuth2Tokens & {
95
90
  user?: {
96
- name /**
97
- * An Integer value that indicates whether the user appears to be a real
98
- * person. Use the value of this claim to mitigate fraud. The possible
99
- * values are: 0 (or Unsupported), 1 (or Unknown), 2 (or LikelyReal). For
100
- * more information, see ASUserDetectionStatus. This claim is present only
101
- * in iOS 14 and later, macOS 11 and later, watchOS 7 and later, tvOS 14
102
- * and later. The claim isn’t present or supported for web-based apps.
103
- */?
104
- /**
105
- * An Integer value that indicates whether the user appears to be a real
106
- * person. Use the value of this claim to mitigate fraud. The possible
107
- * values are: 0 (or Unsupported), 1 (or Unknown), 2 (or LikelyReal). For
108
- * more information, see ASUserDetectionStatus. This claim is present only
109
- * in iOS 14 and later, macOS 11 and later, watchOS 7 and later, tvOS 14
110
- * and later. The claim isn’t present or supported for web-based apps.
111
- */
112
- : {
91
+ name?: {
113
92
  firstName?: string;
114
93
  lastName?: string;
115
94
  };
@@ -50,9 +50,9 @@ const apple = (options) => {
50
50
  tokenEndpoint
51
51
  });
52
52
  },
53
- async verifyIdToken(token, nonce) {
53
+ async verifyIdToken(token, nonce, ctx) {
54
54
  if (options.disableIdTokenSignIn) return false;
55
- if (options.verifyIdToken) return options.verifyIdToken(token, nonce);
55
+ if (options.verifyIdToken) return options.verifyIdToken(token, nonce, ctx);
56
56
  try {
57
57
  const { kid, alg: jwtAlg } = decodeProtectedHeader(token);
58
58
  if (!kid || !jwtAlg) return false;
@@ -1,4 +1,5 @@
1
1
  import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
2
+ import "../oauth2/index.mjs";
2
3
  //#region src/social-providers/atlassian.d.ts
3
4
  interface AtlassianProfile {
4
5
  account_type?: string | undefined;
@@ -21,12 +22,7 @@ interface AtlassianOptions extends ProviderOptions<AtlassianProfile> {
21
22
  declare const atlassian: (options: AtlassianOptions) => {
22
23
  id: "atlassian";
23
24
  name: string;
24
- createAuthorizationURL({
25
- state,
26
- scopes,
27
- codeVerifier,
28
- redirectURI
29
- }: {
25
+ createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }: {
30
26
  state: string;
31
27
  codeVerifier: string;
32
28
  scopes?: string[] | undefined;
@@ -34,11 +30,7 @@ declare const atlassian: (options: AtlassianOptions) => {
34
30
  display?: string | undefined;
35
31
  loginHint?: string | undefined;
36
32
  }): Promise<URL>;
37
- validateAuthorizationCode: ({
38
- code,
39
- codeVerifier,
40
- redirectURI
41
- }: {
33
+ validateAuthorizationCode: ({ code, codeVerifier, redirectURI }: {
42
34
  code: string;
43
35
  redirectURI: string;
44
36
  codeVerifier?: string | undefined;