@better-auth-ui/core 1.6.8 → 1.6.9

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 (102) hide show
  1. package/dist/config/additional-fields-config.js +37 -25
  2. package/dist/config/auth-config.d.ts +9 -9
  3. package/dist/config/auth-config.js +33 -31
  4. package/dist/config/avatar-config.js +1 -0
  5. package/dist/config/email-and-password-config.js +1 -0
  6. package/dist/config/index.d.ts +4 -4
  7. package/dist/config/index.js +4 -0
  8. package/dist/index.d.ts +11 -11
  9. package/dist/index.js +11 -11
  10. package/dist/lib/auth-mutation-keys.d.ts +9 -20
  11. package/dist/lib/auth-mutation-keys.js +69 -56
  12. package/dist/lib/auth-plugin.d.ts +6 -7
  13. package/dist/lib/auth-plugin.js +1 -0
  14. package/dist/lib/auth-query-keys.d.ts +6 -6
  15. package/dist/lib/auth-query-keys.js +41 -38
  16. package/dist/lib/base-paths.js +4 -7
  17. package/dist/lib/create-auth-plugin.d.ts +5 -21
  18. package/dist/lib/create-auth-plugin.js +22 -8
  19. package/dist/lib/deep-partial.js +1 -0
  20. package/dist/lib/localization.d.ts +2 -2
  21. package/dist/lib/localization.js +149 -80
  22. package/dist/lib/provider-names.d.ts +1 -1
  23. package/dist/lib/provider-names.js +48 -41
  24. package/dist/lib/utils.d.ts +1 -1
  25. package/dist/lib/utils.js +111 -43
  26. package/dist/lib/view-paths.d.ts +0 -4
  27. package/dist/lib/view-paths.js +12 -15
  28. package/dist/plugins/api-key/api-key-localization.js +23 -15
  29. package/dist/plugins/api-key/api-key-mutation-keys.d.ts +4 -2
  30. package/dist/plugins/api-key/api-key-mutation-keys.js +10 -14
  31. package/dist/plugins/api-key/api-key-plugin.d.ts +24 -3
  32. package/dist/plugins/api-key/api-key-plugin.js +6 -9
  33. package/dist/plugins/api-key/api-key-query-keys.d.ts +6 -0
  34. package/dist/plugins/api-key/api-key-query-keys.js +7 -0
  35. package/dist/plugins/delete-user/delete-user-localization.d.ts +3 -3
  36. package/dist/plugins/delete-user/delete-user-localization.js +9 -8
  37. package/dist/plugins/delete-user/delete-user-mutation-keys.d.ts +7 -0
  38. package/dist/plugins/delete-user/delete-user-mutation-keys.js +7 -0
  39. package/dist/plugins/delete-user/delete-user-plugin.d.ts +5 -5
  40. package/dist/plugins/delete-user/delete-user-plugin.js +5 -11
  41. package/dist/plugins/magic-link/magic-link-localization.js +7 -7
  42. package/dist/plugins/magic-link/magic-link-mutation-keys.js +17 -8
  43. package/dist/plugins/magic-link/magic-link-plugin.d.ts +3 -3
  44. package/dist/plugins/magic-link/magic-link-plugin.js +7 -11
  45. package/dist/plugins/multi-session/multi-session-localization.js +9 -8
  46. package/dist/plugins/multi-session/multi-session-mutation-keys.d.ts +11 -0
  47. package/dist/plugins/multi-session/multi-session-mutation-keys.js +11 -0
  48. package/dist/plugins/multi-session/multi-session-plugin.d.ts +3 -3
  49. package/dist/plugins/multi-session/multi-session-plugin.js +5 -9
  50. package/dist/plugins/multi-session/multi-session-query-keys.d.ts +6 -0
  51. package/dist/plugins/multi-session/multi-session-query-keys.js +7 -0
  52. package/dist/plugins/organization/organization-localization.d.ts +115 -0
  53. package/dist/plugins/organization/organization-localization.js +114 -0
  54. package/dist/plugins/organization/organization-mutation-keys.d.ts +40 -0
  55. package/dist/plugins/organization/organization-mutation-keys.js +40 -0
  56. package/dist/plugins/organization/organization-plugin.d.ts +152 -0
  57. package/dist/plugins/organization/organization-plugin.js +35 -0
  58. package/dist/plugins/organization/organization-query-keys.d.ts +40 -0
  59. package/dist/plugins/organization/organization-query-keys.js +54 -0
  60. package/dist/plugins/organization/organization-view-paths.d.ts +19 -0
  61. package/dist/plugins/organization/organization-view-paths.js +1 -0
  62. package/dist/plugins/passkey/passkey-localization.js +19 -13
  63. package/dist/plugins/passkey/passkey-mutation-keys.js +14 -19
  64. package/dist/plugins/passkey/passkey-plugin.d.ts +3 -3
  65. package/dist/plugins/passkey/passkey-plugin.js +5 -9
  66. package/dist/plugins/passkey/passkey-query-keys.d.ts +6 -0
  67. package/dist/plugins/passkey/passkey-query-keys.js +7 -0
  68. package/dist/plugins/theme/theme-localization.js +11 -9
  69. package/dist/plugins/theme/theme-plugin.d.ts +3 -3
  70. package/dist/plugins/theme/theme-plugin.js +7 -17
  71. package/dist/plugins/username/username-localization.js +15 -11
  72. package/dist/plugins/username/username-mutation-keys.d.ts +17 -0
  73. package/dist/plugins/username/username-mutation-keys.js +17 -0
  74. package/dist/plugins/username/username-plugin.d.ts +4 -4
  75. package/dist/plugins/username/username-plugin.js +35 -32
  76. package/dist/plugins.d.ts +28 -0
  77. package/dist/plugins.js +28 -18
  78. package/package.json +8 -7
  79. package/src/config/auth-config.ts +1 -1
  80. package/src/lib/auth-mutation-keys.ts +11 -24
  81. package/src/lib/auth-plugin.ts +4 -5
  82. package/src/lib/auth-query-keys.ts +6 -23
  83. package/src/lib/create-auth-plugin.ts +9 -26
  84. package/src/lib/localization.ts +4 -4
  85. package/src/lib/view-paths.ts +0 -4
  86. package/src/plugins/api-key/api-key-mutation-keys.ts +4 -2
  87. package/src/plugins/api-key/api-key-plugin.ts +22 -1
  88. package/src/plugins/api-key/api-key-query-keys.ts +13 -0
  89. package/src/plugins/delete-user/delete-user-localization.ts +3 -3
  90. package/src/plugins/delete-user/delete-user-mutation-keys.ts +7 -0
  91. package/src/plugins/multi-session/multi-session-mutation-keys.ts +11 -0
  92. package/src/plugins/multi-session/multi-session-query-keys.ts +13 -0
  93. package/src/plugins/organization/organization-localization.ts +123 -0
  94. package/src/plugins/organization/organization-mutation-keys.ts +52 -0
  95. package/src/plugins/organization/organization-plugin.ts +112 -0
  96. package/src/plugins/organization/organization-query-keys.ts +86 -0
  97. package/src/plugins/organization/organization-view-paths.ts +20 -0
  98. package/src/plugins/passkey/passkey-query-keys.ts +13 -0
  99. package/src/plugins/username/username-mutation-keys.ts +17 -0
  100. package/src/plugins.ts +28 -0
  101. package/dist/plugins/index.d.ts +0 -17
  102. package/src/plugins/index.ts +0 -17
@@ -1,27 +1,39 @@
1
- //#region src/config/additional-fields-config.ts
2
- function e(e, t) {
3
- if (e.type === "boolean") return t === "on" || t === "true";
4
- if (t != null) {
5
- if (t === "") return null;
6
- if (e.type === "number") {
7
- let e = Number(t);
8
- return Number.isNaN(e) ? void 0 : e;
9
- }
10
- if (e.type === "date") {
11
- let e = new Date(t);
12
- return Number.isNaN(e.getTime()) ? void 0 : e;
13
- }
14
- return t;
15
- }
1
+ /**
2
+ * Convert a raw form value into the JS value Better Auth expects.
3
+ * Returns `null` for blank input (explicit clear), `undefined` when omitted
4
+ * or unparseable. Booleans always return `true`/`false`.
5
+ */
6
+ export function parseAdditionalFieldValue(field, raw) {
7
+ if (field.type === "boolean") {
8
+ // FormData: checked checkbox/switch sends "on"; unchecked sends nothing.
9
+ return raw === "on" || raw === "true";
10
+ }
11
+ if (raw == null)
12
+ return undefined;
13
+ if (raw === "")
14
+ return null;
15
+ if (field.type === "number") {
16
+ const parsed = Number(raw);
17
+ return Number.isNaN(parsed) ? undefined : parsed;
18
+ }
19
+ if (field.type === "date") {
20
+ const parsed = new Date(raw);
21
+ return Number.isNaN(parsed.getTime()) ? undefined : parsed;
22
+ }
23
+ return raw;
16
24
  }
17
- function t(e) {
18
- if (e.inputType) return e.inputType;
19
- switch (e.type) {
20
- case "number": return "number";
21
- case "boolean": return "switch";
22
- case "date": return "date";
23
- default: return "input";
24
- }
25
+ /** Resolve the effective `inputType`, defaulting based on `field.type`. */
26
+ export function resolveInputType(field) {
27
+ if (field.inputType)
28
+ return field.inputType;
29
+ switch (field.type) {
30
+ case "number":
31
+ return "number";
32
+ case "boolean":
33
+ return "switch";
34
+ case "date":
35
+ return "date";
36
+ default:
37
+ return "input";
38
+ }
25
39
  }
26
- //#endregion
27
- export { e as parseAdditionalFieldValue, t as resolveInputType };
@@ -1,11 +1,11 @@
1
- import { SocialProvider } from 'better-auth/social-providers';
2
- import { AuthPlugin } from '../lib/auth-plugin';
3
- import { BasePaths } from '../lib/base-paths';
4
- import { Localization } from '../lib/localization';
5
- import { ViewPaths } from '../lib/view-paths';
6
- import { AdditionalFields } from './additional-fields-config';
7
- import { AvatarConfig } from './avatar-config';
8
- import { EmailAndPasswordConfig } from './email-and-password-config';
1
+ import type { SocialProvider } from "better-auth/social-providers";
2
+ import type { AuthPlugin } from "../lib/auth-plugin";
3
+ import { type BasePaths } from "../lib/base-paths";
4
+ import { type Localization } from "../lib/localization";
5
+ import { type ViewPaths } from "../lib/view-paths";
6
+ import type { AdditionalFields } from "./additional-fields-config";
7
+ import type { AvatarConfig } from "./avatar-config";
8
+ import type { EmailAndPasswordConfig } from "./email-and-password-config";
9
9
  /**
10
10
  * Core authentication configuration interface.
11
11
  *
@@ -81,4 +81,4 @@ export interface AuthConfig {
81
81
  replace?: boolean;
82
82
  }) => void;
83
83
  }
84
- export declare const defaultAuthConfig: AuthConfig;
84
+ export declare const defaultAuthConfig: Omit<AuthConfig, "authClient">;
@@ -1,32 +1,34 @@
1
- import { basePaths as e } from "../lib/base-paths.js";
2
- import { localization as t } from "../lib/localization.js";
3
- import { resizeAvatar as n } from "../lib/utils.js";
4
- import { viewPaths as r } from "../lib/view-paths.js";
5
- //#region src/config/auth-config.ts
6
- var i = {
7
- avatar: {
8
- enabled: !0,
9
- resize: n,
10
- size: 256,
11
- extension: "png"
12
- },
13
- basePaths: e,
14
- baseURL: "",
15
- emailAndPassword: {
16
- enabled: !0,
17
- forgotPassword: !0,
18
- name: !0,
19
- rememberMe: !1,
20
- minPasswordLength: 8,
21
- maxPasswordLength: 128
22
- },
23
- plugins: [],
24
- redirectTo: "/",
25
- viewPaths: r,
26
- localization: t,
27
- navigate: ({ to: e, replace: t }) => {
28
- t ? window.location.replace(e) : window.location.href = e;
29
- }
1
+ import { basePaths } from "../lib/base-paths";
2
+ import { localization } from "../lib/localization";
3
+ import { resizeAvatar } from "../lib/utils";
4
+ import { viewPaths } from "../lib/view-paths";
5
+ export const defaultAuthConfig = {
6
+ avatar: {
7
+ enabled: true,
8
+ resize: resizeAvatar,
9
+ size: 256,
10
+ extension: "png"
11
+ },
12
+ basePaths,
13
+ baseURL: "",
14
+ emailAndPassword: {
15
+ enabled: true,
16
+ forgotPassword: true,
17
+ name: true,
18
+ rememberMe: false,
19
+ minPasswordLength: 8,
20
+ maxPasswordLength: 128
21
+ },
22
+ plugins: [],
23
+ redirectTo: "/",
24
+ viewPaths,
25
+ localization,
26
+ navigate: ({ to, replace }) => {
27
+ if (replace) {
28
+ window.location.replace(to);
29
+ }
30
+ else {
31
+ window.location.href = to;
32
+ }
33
+ }
30
34
  };
31
- //#endregion
32
- export { i as defaultAuthConfig };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- export * from './additional-fields-config';
2
- export * from './auth-config';
3
- export * from './avatar-config';
4
- export * from './email-and-password-config';
1
+ export * from "./additional-fields-config";
2
+ export * from "./auth-config";
3
+ export * from "./avatar-config";
4
+ export * from "./email-and-password-config";
@@ -0,0 +1,4 @@
1
+ export * from "./additional-fields-config";
2
+ export * from "./auth-config";
3
+ export * from "./avatar-config";
4
+ export * from "./email-and-password-config";
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export * from './config';
2
- export * from './lib/auth-mutation-keys';
3
- export * from './lib/auth-plugin';
4
- export * from './lib/auth-query-keys';
5
- export * from './lib/base-paths';
6
- export * from './lib/create-auth-plugin';
7
- export * from './lib/deep-partial';
8
- export * from './lib/localization';
9
- export * from './lib/provider-names';
10
- export * from './lib/utils';
11
- export * from './lib/view-paths';
1
+ export * from "./config";
2
+ export * from "./lib/auth-mutation-keys";
3
+ export * from "./lib/auth-plugin";
4
+ export * from "./lib/auth-query-keys";
5
+ export * from "./lib/base-paths";
6
+ export * from "./lib/create-auth-plugin";
7
+ export * from "./lib/deep-partial";
8
+ export * from "./lib/localization";
9
+ export * from "./lib/provider-names";
10
+ export * from "./lib/utils";
11
+ export * from "./lib/view-paths";
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { parseAdditionalFieldValue as e, resolveInputType as t } from "./config/additional-fields-config.js";
2
- import { basePaths as n } from "./lib/base-paths.js";
3
- import { localization as r } from "./lib/localization.js";
4
- import { deepmerge as i, fileToBase64 as a, resizeAvatar as o } from "./lib/utils.js";
5
- import { viewPaths as s } from "./lib/view-paths.js";
6
- import { defaultAuthConfig as c } from "./config/auth-config.js";
7
- import { authMutationKeys as l } from "./lib/auth-mutation-keys.js";
8
- import { authQueryKeys as u } from "./lib/auth-query-keys.js";
9
- import { createAuthPlugin as d } from "./lib/create-auth-plugin.js";
10
- import { getProviderName as f, providerNames as p } from "./lib/provider-names.js";
11
- export { l as authMutationKeys, u as authQueryKeys, n as basePaths, d as createAuthPlugin, i as deepmerge, c as defaultAuthConfig, a as fileToBase64, f as getProviderName, r as localization, e as parseAdditionalFieldValue, p as providerNames, o as resizeAvatar, t as resolveInputType, s as viewPaths };
1
+ export * from "./config";
2
+ export * from "./lib/auth-mutation-keys";
3
+ export * from "./lib/auth-plugin";
4
+ export * from "./lib/auth-query-keys";
5
+ export * from "./lib/base-paths";
6
+ export * from "./lib/create-auth-plugin";
7
+ export * from "./lib/deep-partial";
8
+ export * from "./lib/localization";
9
+ export * from "./lib/provider-names";
10
+ export * from "./lib/utils";
11
+ export * from "./lib/view-paths";
@@ -18,6 +18,14 @@
18
18
  * etc.) — the mutation cache entries line up regardless of which framework
19
19
  * package the mutation options factory came from.
20
20
  *
21
+ * Plugin-specific mutation keys live alongside their plugin (e.g.
22
+ * `apiKeyMutationKeys`, `organizationMutationKeys`, `passkeyMutationKeys`,
23
+ * `magicLinkMutationKeys`, `multiSessionMutationKeys`, `usernameMutationKeys`,
24
+ * `deleteUserMutationKeys`). Plugin-contributed sign-in strategies stay
25
+ * under the shared `["auth", "signIn", ...]` namespace so
26
+ * `useIsMutating({ mutationKey: authMutationKeys.signIn.all })` still
27
+ * matches them.
28
+ *
21
29
  * For query keys, see `authQueryKeys` in `./auth-query-keys`.
22
30
  */
23
31
  export declare const authMutationKeys: {
@@ -25,14 +33,12 @@ export declare const authMutationKeys: {
25
33
  readonly all: readonly ["auth"];
26
34
  /** Sign-in mutations, grouped by strategy. */
27
35
  readonly signIn: {
28
- /** Prefix matching every sign-in mutation. */
36
+ /** Prefix matching every sign-in mutation (including plugin strategies). */
29
37
  readonly all: readonly ["auth", "signIn"];
30
38
  /** Key for `signIn.email`. */
31
39
  readonly email: readonly ["auth", "signIn", "email"];
32
40
  /** Key for `signIn.social`. */
33
41
  readonly social: readonly ["auth", "signIn", "social"];
34
- /** Key for `signIn.username`. */
35
- readonly username: readonly ["auth", "signIn", "username"];
36
42
  };
37
43
  /** Sign-up mutations, grouped by strategy. */
38
44
  readonly signUp: {
@@ -49,21 +55,10 @@ export declare const authMutationKeys: {
49
55
  readonly resetPassword: readonly ["auth", "resetPassword"];
50
56
  /** Key for `sendVerificationEmail`. */
51
57
  readonly sendVerificationEmail: readonly ["auth", "sendVerificationEmail"];
52
- /** Multi-session mutations. */
53
- readonly multiSession: {
54
- /** Prefix matching every multi-session mutation. */
55
- readonly all: readonly ["auth", "multiSession"];
56
- /** Key for `multiSession.revoke`. */
57
- readonly revoke: readonly ["auth", "multiSession", "revoke"];
58
- /** Key for `multiSession.setActive`. */
59
- readonly setActive: readonly ["auth", "multiSession", "setActive"];
60
- };
61
58
  /** Key for `changeEmail`. */
62
59
  readonly changeEmail: readonly ["auth", "changeEmail"];
63
60
  /** Key for `changePassword`. */
64
61
  readonly changePassword: readonly ["auth", "changePassword"];
65
- /** Key for `deleteUser`. */
66
- readonly deleteUser: readonly ["auth", "deleteUser"];
67
62
  /** Key for `linkSocial`. */
68
63
  readonly linkSocial: readonly ["auth", "linkSocial"];
69
64
  /** Key for `revokeSession`. */
@@ -72,10 +67,4 @@ export declare const authMutationKeys: {
72
67
  readonly unlinkAccount: readonly ["auth", "unlinkAccount"];
73
68
  /** Key for `updateUser`. */
74
69
  readonly updateUser: readonly ["auth", "updateUser"];
75
- /**
76
- * Key for `isUsernameAvailable`. This is technically a read, but it's
77
- * exposed via better-auth's mutation surface and lives under the mutation
78
- * factories for parity with other username flows.
79
- */
80
- readonly isUsernameAvailable: readonly ["auth", "isUsernameAvailable"];
81
70
  };
@@ -1,57 +1,70 @@
1
- //#region src/lib/auth-mutation-keys.ts
2
- var e = {
3
- all: ["auth"],
4
- signIn: {
5
- all: ["auth", "signIn"],
6
- email: [
7
- "auth",
8
- "signIn",
9
- "email"
10
- ],
11
- social: [
12
- "auth",
13
- "signIn",
14
- "social"
15
- ],
16
- username: [
17
- "auth",
18
- "signIn",
19
- "username"
20
- ]
21
- },
22
- signUp: {
23
- all: ["auth", "signUp"],
24
- email: [
25
- "auth",
26
- "signUp",
27
- "email"
28
- ]
29
- },
30
- signOut: ["auth", "signOut"],
31
- requestPasswordReset: ["auth", "requestPasswordReset"],
32
- resetPassword: ["auth", "resetPassword"],
33
- sendVerificationEmail: ["auth", "sendVerificationEmail"],
34
- multiSession: {
35
- all: ["auth", "multiSession"],
36
- revoke: [
37
- "auth",
38
- "multiSession",
39
- "revoke"
40
- ],
41
- setActive: [
42
- "auth",
43
- "multiSession",
44
- "setActive"
45
- ]
46
- },
47
- changeEmail: ["auth", "changeEmail"],
48
- changePassword: ["auth", "changePassword"],
49
- deleteUser: ["auth", "deleteUser"],
50
- linkSocial: ["auth", "linkSocial"],
51
- revokeSession: ["auth", "revokeSession"],
52
- unlinkAccount: ["auth", "unlinkAccount"],
53
- updateUser: ["auth", "updateUser"],
54
- isUsernameAvailable: ["auth", "isUsernameAvailable"]
1
+ /**
2
+ * Hierarchical mutation key factory for every Better Auth mutation managed by
3
+ * this library.
4
+ *
5
+ * Mutation keys are mostly used for `useIsMutating` and global
6
+ * `MutationCache` observers (e.g. toast handling), so the keys are static
7
+ * tuples rather than parameterised factories. Each grouping exposes an
8
+ * `all` prefix so consumers can match a whole feature at once:
9
+ *
10
+ * ```ts
11
+ * useIsMutating({ mutationKey: authMutationKeys.all })
12
+ * useIsMutating({ mutationKey: authMutationKeys.signIn.all })
13
+ * useIsMutating({ mutationKey: authMutationKeys.signIn.email })
14
+ * ```
15
+ *
16
+ * This factory lives in `@better-auth-ui/core` so it can be shared across
17
+ * framework packages (`@better-auth-ui/react`, a future `/solid` package,
18
+ * etc.) — the mutation cache entries line up regardless of which framework
19
+ * package the mutation options factory came from.
20
+ *
21
+ * Plugin-specific mutation keys live alongside their plugin (e.g.
22
+ * `apiKeyMutationKeys`, `organizationMutationKeys`, `passkeyMutationKeys`,
23
+ * `magicLinkMutationKeys`, `multiSessionMutationKeys`, `usernameMutationKeys`,
24
+ * `deleteUserMutationKeys`). Plugin-contributed sign-in strategies stay
25
+ * under the shared `["auth", "signIn", ...]` namespace so
26
+ * `useIsMutating({ mutationKey: authMutationKeys.signIn.all })` still
27
+ * matches them.
28
+ *
29
+ * For query keys, see `authQueryKeys` in `./auth-query-keys`.
30
+ */
31
+ export const authMutationKeys = {
32
+ /** Root key for every Better Auth mutation. */
33
+ all: ["auth"],
34
+ /** Sign-in mutations, grouped by strategy. */
35
+ signIn: {
36
+ /** Prefix matching every sign-in mutation (including plugin strategies). */
37
+ all: ["auth", "signIn"],
38
+ /** Key for `signIn.email`. */
39
+ email: ["auth", "signIn", "email"],
40
+ /** Key for `signIn.social`. */
41
+ social: ["auth", "signIn", "social"]
42
+ },
43
+ /** Sign-up mutations, grouped by strategy. */
44
+ signUp: {
45
+ /** Prefix matching every sign-up mutation. */
46
+ all: ["auth", "signUp"],
47
+ /** Key for `signUp.email`. */
48
+ email: ["auth", "signUp", "email"]
49
+ },
50
+ /** Key for `signOut`. */
51
+ signOut: ["auth", "signOut"],
52
+ /** Key for `requestPasswordReset`. */
53
+ requestPasswordReset: ["auth", "requestPasswordReset"],
54
+ /** Key for `resetPassword`. */
55
+ resetPassword: ["auth", "resetPassword"],
56
+ /** Key for `sendVerificationEmail`. */
57
+ sendVerificationEmail: ["auth", "sendVerificationEmail"],
58
+ /** Key for `changeEmail`. */
59
+ changeEmail: ["auth", "changeEmail"],
60
+ /** Key for `changePassword`. */
61
+ changePassword: ["auth", "changePassword"],
62
+ /** Key for `linkSocial`. */
63
+ linkSocial: ["auth", "linkSocial"],
64
+ /** Key for `revokeSession`. */
65
+ revokeSession: ["auth", "revokeSession"],
66
+ /** Key for `unlinkAccount`. */
67
+ unlinkAccount: ["auth", "unlinkAccount"],
68
+ /** Key for `updateUser`. */
69
+ updateUser: ["auth", "updateUser"]
55
70
  };
56
- //#endregion
57
- export { e as authMutationKeys };
@@ -1,15 +1,18 @@
1
- import { AdditionalFields } from '../config/additional-fields-config';
1
+ import type { AdditionalFields } from "../config/additional-fields-config";
2
2
  /**
3
3
  * View-path contributions kept on the plugin object.
4
4
  *
5
5
  * Plugins that add routable sub-pages (e.g. `magicLinkPlugin` adds
6
6
  * `/auth/magic-link`) declare the URL segment under the matching section.
7
7
  * Read at runtime via `useAuthPlugin(plugin).viewPaths.*`.
8
+ *
9
+ * Plugin-specific namespaces (e.g. organization route segments) are merged
10
+ * via module augmentation from that plugin’s module — not declared here.
8
11
  */
9
- export type AuthPluginViewPaths = {
12
+ export interface AuthPluginViewPaths {
10
13
  auth?: Record<string, string>;
11
14
  settings?: Record<string, string>;
12
- };
15
+ }
13
16
  /**
14
17
  * Core authentication plugin interface.
15
18
  *
@@ -32,10 +35,6 @@ export interface AuthPluginBase {
32
35
  * user-defined additionalFields in the auth config.
33
36
  */
34
37
  additionalFields?: AdditionalFields;
35
- /**
36
- * Additional properties contributed by the plugin.
37
- */
38
- [key: string]: unknown;
39
38
  }
40
39
  /**
41
40
  * Composable module-augmentation slot for narrowing the plugin type returned
@@ -0,0 +1 @@
1
+ export {};
@@ -16,6 +16,12 @@
16
16
  * etc.) and across client- and server-side query variants — the cache
17
17
  * entries line up regardless of which query options factory produced them.
18
18
  *
19
+ * Plugin-specific query keys live alongside their plugin (e.g.
20
+ * `apiKeyQueryKeys`, `organizationQueryKeys`, `passkeyQueryKeys`,
21
+ * `multiSessionQueryKeys`) and chain off `authQueryKeys.user(userId)` so
22
+ * everything still sits under the shared `["auth", "user", userId, ...]`
23
+ * subtree.
24
+ *
19
25
  * For mutation keys, see `authMutationKeys` in `./auth-mutation-keys`.
20
26
  */
21
27
  export declare const authQueryKeys: {
@@ -27,12 +33,6 @@ export declare const authQueryKeys: {
27
33
  readonly users: () => readonly ["auth", "user"];
28
34
  /** Prefix for every query scoped to a specific user. */
29
35
  readonly user: (userId: string | undefined) => readonly ["auth", "user", string | undefined];
30
- /** Key for `multiSession.listDeviceSessions` for the given user. */
31
- readonly listDeviceSessions: <TQuery = undefined>(userId: string | undefined, query?: TQuery) => readonly ["auth", "user", string | undefined, "listDeviceSessions", NonNullable<TQuery> | null];
32
- /** Key for the user's passkey list. */
33
- readonly listPasskeys: <TQuery = undefined>(userId: string | undefined, query?: TQuery) => readonly ["auth", "user", string | undefined, "listPasskeys", NonNullable<TQuery> | null];
34
- /** Key for the user's API keys list (`apiKey.list`). */
35
- readonly listApiKeys: <TQuery = undefined>(userId: string | undefined, query?: TQuery) => readonly ["auth", "user", string | undefined, "listApiKeys", NonNullable<TQuery> | null];
36
36
  /** Key for `accountInfo` for the given user. */
37
37
  readonly accountInfo: <TQuery = undefined>(userId: string | undefined, query?: TQuery) => readonly ["auth", "user", string | undefined, "accountInfo", NonNullable<TQuery> | null];
38
38
  /** Key for `listAccounts` for the given user. */
@@ -1,39 +1,42 @@
1
- //#region src/lib/auth-query-keys.ts
2
- var e = {
3
- all: ["auth"],
4
- session: ["auth", "getSession"],
5
- users: () => [...e.all, "user"],
6
- user: (t) => [...e.users(), t],
7
- listDeviceSessions: (t, n) => [
8
- ...e.user(t),
9
- "listDeviceSessions",
10
- n ?? null
11
- ],
12
- listPasskeys: (t, n) => [
13
- ...e.user(t),
14
- "listPasskeys",
15
- n ?? null
16
- ],
17
- listApiKeys: (t, n) => [
18
- ...e.user(t),
19
- "listApiKeys",
20
- n ?? null
21
- ],
22
- accountInfo: (t, n) => [
23
- ...e.user(t),
24
- "accountInfo",
25
- n ?? null
26
- ],
27
- listAccounts: (t, n) => [
28
- ...e.user(t),
29
- "listAccounts",
30
- n ?? null
31
- ],
32
- listSessions: (t, n) => [
33
- ...e.user(t),
34
- "listSessions",
35
- n ?? null
36
- ]
1
+ /**
2
+ * Hierarchical query key factory for every Better Auth query managed by
3
+ * this library.
4
+ *
5
+ * Keys are nested — higher-level keys are valid prefixes of their
6
+ * descendants so a single call can invalidate a whole subtree:
7
+ *
8
+ * ```ts
9
+ * queryClient.invalidateQueries({ queryKey: authQueryKeys.all })
10
+ * queryClient.invalidateQueries({ queryKey: authQueryKeys.user(userId) })
11
+ * queryClient.invalidateQueries({ queryKey: authQueryKeys.session })
12
+ * ```
13
+ *
14
+ * This factory lives in `@better-auth-ui/core` so it can be shared across
15
+ * framework packages (`@better-auth-ui/react`, a future `/solid` package,
16
+ * etc.) and across client- and server-side query variants — the cache
17
+ * entries line up regardless of which query options factory produced them.
18
+ *
19
+ * Plugin-specific query keys live alongside their plugin (e.g.
20
+ * `apiKeyQueryKeys`, `organizationQueryKeys`, `passkeyQueryKeys`,
21
+ * `multiSessionQueryKeys`) and chain off `authQueryKeys.user(userId)` so
22
+ * everything still sits under the shared `["auth", "user", userId, ...]`
23
+ * subtree.
24
+ *
25
+ * For mutation keys, see `authMutationKeys` in `./auth-mutation-keys`.
26
+ */
27
+ export const authQueryKeys = {
28
+ /** Root key for every Better Auth query. */
29
+ all: ["auth"],
30
+ /** Key for the current `getSession` query. */
31
+ session: ["auth", "getSession"],
32
+ /** Prefix for every per-user query. */
33
+ users: () => [...authQueryKeys.all, "user"],
34
+ /** Prefix for every query scoped to a specific user. */
35
+ user: (userId) => [...authQueryKeys.users(), userId],
36
+ /** Key for `accountInfo` for the given user. */
37
+ accountInfo: (userId, query) => [...authQueryKeys.user(userId), "accountInfo", query ?? null],
38
+ /** Key for `listAccounts` for the given user. */
39
+ listAccounts: (userId, query) => [...authQueryKeys.user(userId), "listAccounts", query ?? null],
40
+ /** Key for `listSessions` for the given user. */
41
+ listSessions: (userId, query) => [...authQueryKeys.user(userId), "listSessions", query ?? null]
37
42
  };
38
- //#endregion
39
- export { e as authQueryKeys };
@@ -1,8 +1,5 @@
1
- //#region src/lib/base-paths.ts
2
- var e = {
3
- auth: "/auth",
4
- settings: "/settings",
5
- organization: "/organization"
1
+ export const basePaths = {
2
+ auth: "/auth",
3
+ settings: "/settings",
4
+ organization: "/organization"
6
5
  };
7
- //#endregion
8
- export { e as basePaths };
@@ -1,37 +1,21 @@
1
+ import type { AuthPlugin } from "./auth-plugin";
1
2
  /**
2
- * Creates a plugin factory and attaches its `id` as a static property.
3
- *
4
- * Lifts the plugin's `id` out of the factory's runtime output so consumers
5
- * (e.g. `useAuthPlugin`) can read it without invoking the factory. This lets
6
- * plugins keep required options (like `themePlugin`'s `setTheme`) without
7
- * forcing every factory to be callable with zero arguments.
8
- *
9
- * The returned factory:
10
- * - is callable with the original arguments and returns the factory's result
11
- * merged with `{ id }`
12
- * - exposes `id` as a static property so it can be read at registration or
13
- * lookup time without allocating a plugin instance
14
- *
15
- * Type safety for the plugin's shape is enforced at the registration site
16
- * (`<AuthProvider plugins={[…]} />`) where `plugins` is typed as `AuthPlugin[]`.
3
+ * Creates a plugin factory and attaches its `id` as a static property so
4
+ * consumers (e.g. `useAuthPlugin`) can look it up without invoking the
5
+ * factory.
17
6
  *
18
7
  * @example
19
8
  * ```ts
20
9
  * export const themePlugin = createAuthPlugin(
21
10
  * "theme",
22
11
  * (options: ThemePluginOptions) => ({
23
- * localization: { ...themeLocalization, ...options.localization },
24
- * theme: options.theme ?? "system",
25
12
  * setTheme: options.setTheme,
26
13
  * themes: options.themes ?? ["system", "light", "dark"]
27
14
  * })
28
15
  * )
29
- *
30
- * themePlugin.id // "theme"
31
- * themePlugin({ setTheme }) // { id: "theme", localization, theme, setTheme, themes }
32
16
  * ```
33
17
  */
34
- export declare function createAuthPlugin<const TId extends string, TArgs extends unknown[], TResult extends object>(id: TId, factory: (...args: TArgs) => TResult): ((...args: TArgs) => Omit<TResult, "id"> & {
18
+ export declare function createAuthPlugin<const TId extends string, TArgs extends unknown[], TResult extends Omit<AuthPlugin, "id"> & object>(id: TId, factory: (...args: TArgs) => TResult): ((...args: TArgs) => TResult & {
35
19
  id: TId;
36
20
  }) & {
37
21
  id: TId;