@better-auth-ui/heroui 1.6.2 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/dist/components/auth/additional-field.d.ts +4 -0
  2. package/dist/components/auth/additional-field.js +270 -0
  3. package/dist/components/auth/auth-provider.d.ts +4 -6
  4. package/dist/components/auth/auth-provider.js +12 -11
  5. package/dist/components/auth/auth.d.ts +1 -1
  6. package/dist/components/auth/auth.js +54 -28
  7. package/dist/components/{settings/security → auth/delete-user}/danger-zone.d.ts +3 -4
  8. package/dist/components/{settings/security → auth/delete-user}/danger-zone.js +1 -1
  9. package/dist/components/{settings/security → auth/delete-user}/delete-user.d.ts +1 -1
  10. package/dist/components/auth/delete-user/delete-user.js +95 -0
  11. package/dist/components/{email → auth/email}/email-changed-email.d.ts +2 -2
  12. package/dist/components/{email → auth/email}/email-changed-email.js +7 -7
  13. package/dist/components/{email → auth/email}/email-verification-email.d.ts +2 -2
  14. package/dist/components/{email → auth/email}/email-verification-email.js +7 -7
  15. package/dist/components/auth/email/magic-link-email.d.ts +3 -0
  16. package/dist/components/{email → auth/email}/magic-link-email.js +7 -7
  17. package/dist/components/auth/email/new-device-email.d.ts +3 -0
  18. package/dist/components/{email → auth/email}/new-device-email.js +7 -7
  19. package/dist/components/auth/email/otp-email.d.ts +3 -0
  20. package/dist/components/{email → auth/email}/otp-email.js +6 -6
  21. package/dist/components/{email → auth/email}/password-changed-email.d.ts +2 -2
  22. package/dist/components/{email → auth/email}/password-changed-email.js +7 -7
  23. package/dist/components/{email → auth/email}/reset-password-email.d.ts +2 -2
  24. package/dist/components/{email → auth/email}/reset-password-email.js +7 -7
  25. package/dist/components/auth/error-toaster.d.ts +1 -0
  26. package/dist/components/auth/error-toaster.js +17 -0
  27. package/dist/components/auth/forgot-password.d.ts +2 -2
  28. package/dist/components/auth/forgot-password.js +42 -42
  29. package/dist/components/auth/magic-link/magic-link-button.d.ts +11 -0
  30. package/dist/components/auth/magic-link/magic-link-button.js +20 -0
  31. package/dist/components/auth/magic-link/magic-link.d.ts +16 -0
  32. package/dist/components/auth/magic-link/magic-link.js +87 -0
  33. package/dist/components/{settings/account → auth/multi-session}/manage-account.d.ts +2 -6
  34. package/dist/components/auth/multi-session/manage-account.js +49 -0
  35. package/dist/components/{settings/account → auth/multi-session}/manage-accounts.d.ts +1 -1
  36. package/dist/components/auth/multi-session/manage-accounts.js +34 -0
  37. package/dist/components/{user/switch-account-menu.d.ts → auth/multi-session/switch-account-submenu-content.d.ts} +3 -3
  38. package/dist/components/auth/multi-session/switch-account-submenu-content.js +29 -0
  39. package/dist/components/{user/switch-account-item.d.ts → auth/multi-session/switch-account-submenu-item.d.ts} +2 -2
  40. package/dist/components/auth/multi-session/switch-account-submenu-item.js +20 -0
  41. package/dist/components/auth/multi-session/switch-account-submenu.d.ts +13 -0
  42. package/dist/components/auth/multi-session/switch-account-submenu.js +24 -0
  43. package/dist/components/auth/passkey/passkey-button.d.ts +6 -0
  44. package/dist/components/auth/passkey/passkey-button.js +24 -0
  45. package/dist/components/auth/passkey/passkey.js +45 -0
  46. package/dist/components/{settings/security → auth/passkey}/passkeys.d.ts +1 -1
  47. package/dist/components/auth/passkey/passkeys.js +106 -0
  48. package/dist/components/auth/provider-button.d.ts +13 -0
  49. package/dist/components/auth/provider-button.js +25 -0
  50. package/dist/components/auth/provider-buttons.d.ts +3 -10
  51. package/dist/components/auth/provider-buttons.js +14 -22
  52. package/dist/components/auth/reset-password.d.ts +1 -1
  53. package/dist/components/auth/reset-password.js +110 -110
  54. package/dist/components/{settings → auth/settings}/account/account-settings.d.ts +5 -2
  55. package/dist/components/auth/settings/account/account-settings.js +20 -0
  56. package/dist/components/auth/settings/account/change-avatar.js +89 -0
  57. package/dist/components/{settings → auth/settings}/account/change-email.d.ts +1 -1
  58. package/dist/components/{settings → auth/settings}/account/change-email.js +17 -20
  59. package/dist/components/{settings → auth/settings}/account/user-profile.d.ts +3 -4
  60. package/dist/components/auth/settings/account/user-profile.js +86 -0
  61. package/dist/components/auth/settings/security/active-session.js +59 -0
  62. package/dist/components/{settings → auth/settings}/security/active-sessions.d.ts +1 -1
  63. package/dist/components/auth/settings/security/active-sessions.js +34 -0
  64. package/dist/components/{settings → auth/settings}/security/change-password.d.ts +1 -1
  65. package/dist/components/auth/settings/security/change-password.js +189 -0
  66. package/dist/components/auth/settings/security/linked-account.js +56 -0
  67. package/dist/components/{settings → auth/settings}/security/linked-accounts.d.ts +1 -1
  68. package/dist/components/auth/settings/security/linked-accounts.js +45 -0
  69. package/dist/components/{settings → auth/settings}/security/security-settings.d.ts +1 -1
  70. package/dist/components/auth/settings/security/security-settings.js +22 -0
  71. package/dist/components/auth/settings/settings.js +45 -0
  72. package/dist/components/auth/sign-in.d.ts +1 -1
  73. package/dist/components/auth/sign-in.js +64 -100
  74. package/dist/components/auth/sign-out.js +11 -11
  75. package/dist/components/auth/sign-up.d.ts +1 -1
  76. package/dist/components/auth/sign-up.js +123 -157
  77. package/dist/components/{settings/account → auth/theme}/appearance.d.ts +3 -6
  78. package/dist/components/auth/theme/appearance.js +72 -0
  79. package/dist/components/auth/theme/theme-toggle-item.d.ts +5 -0
  80. package/dist/components/auth/theme/theme-toggle-item.js +58 -0
  81. package/dist/components/auth/user/user-avatar.js +29 -0
  82. package/dist/components/{user → auth/user}/user-button.d.ts +2 -6
  83. package/dist/components/auth/user/user-button.js +55 -0
  84. package/dist/components/auth/user/user-view.js +37 -0
  85. package/dist/components/auth/username/sign-in-username.d.ts +14 -0
  86. package/dist/components/auth/username/sign-in-username.js +142 -0
  87. package/dist/components/auth/username/username-field.d.ts +8 -0
  88. package/dist/components/auth/username/username-field.js +51 -0
  89. package/dist/email.d.ts +7 -0
  90. package/dist/email.js +9 -0
  91. package/dist/index.d.ts +13 -27
  92. package/dist/index.js +22 -36
  93. package/dist/lib/auth/auth-plugin.d.ts +44 -0
  94. package/dist/lib/auth/delete-user-plugin.d.ts +17 -0
  95. package/dist/lib/auth/delete-user-plugin.js +10 -0
  96. package/dist/lib/auth/magic-link-plugin.d.ts +31 -0
  97. package/dist/lib/auth/magic-link-plugin.js +13 -0
  98. package/dist/lib/auth/multi-session-plugin.d.ts +18 -0
  99. package/dist/lib/auth/multi-session-plugin.js +12 -0
  100. package/dist/lib/auth/passkey-plugin.d.ts +20 -0
  101. package/dist/lib/auth/passkey-plugin.js +12 -0
  102. package/dist/lib/auth/theme-plugin.d.ts +68 -0
  103. package/dist/lib/auth/theme-plugin.js +23 -0
  104. package/dist/lib/auth/username-plugin.d.ts +63 -0
  105. package/dist/lib/auth/username-plugin.js +18 -0
  106. package/dist/plugins.d.ts +20 -0
  107. package/dist/plugins.js +21 -0
  108. package/package.json +22 -22
  109. package/src/components/auth/additional-field.tsx +554 -0
  110. package/src/components/auth/auth-provider.tsx +8 -5
  111. package/src/components/auth/auth.tsx +100 -36
  112. package/src/components/{settings/security → auth/delete-user}/danger-zone.tsx +3 -10
  113. package/src/components/{settings/security → auth/delete-user}/delete-user.tsx +31 -24
  114. package/src/components/{email → auth/email}/email-changed-email.tsx +2 -2
  115. package/src/components/{email → auth/email}/email-verification-email.tsx +2 -2
  116. package/src/components/{email → auth/email}/magic-link-email.tsx +2 -2
  117. package/src/components/{email → auth/email}/new-device-email.tsx +2 -2
  118. package/src/components/{email → auth/email}/otp-email.tsx +2 -2
  119. package/src/components/{email → auth/email}/password-changed-email.tsx +2 -2
  120. package/src/components/{email → auth/email}/reset-password-email.tsx +2 -2
  121. package/src/components/auth/error-toaster.tsx +25 -0
  122. package/src/components/auth/forgot-password.tsx +15 -13
  123. package/src/components/auth/magic-link/magic-link-button.tsx +61 -0
  124. package/src/components/auth/{magic-link.tsx → magic-link/magic-link.tsx} +52 -57
  125. package/src/components/{settings/account → auth/multi-session}/manage-account.tsx +15 -15
  126. package/src/components/{settings/account → auth/multi-session}/manage-accounts.tsx +16 -12
  127. package/src/components/{user/switch-account-menu.tsx → auth/multi-session/switch-account-submenu-content.tsx} +19 -17
  128. package/src/components/{user/switch-account-item.tsx → auth/multi-session/switch-account-submenu-item.tsx} +18 -8
  129. package/src/components/auth/multi-session/switch-account-submenu.tsx +50 -0
  130. package/src/components/auth/passkey/passkey-button.tsx +56 -0
  131. package/src/components/{settings/security → auth/passkey}/passkey.tsx +21 -9
  132. package/src/components/auth/passkey/passkeys.tsx +196 -0
  133. package/src/components/auth/provider-button.tsx +65 -0
  134. package/src/components/auth/provider-buttons.tsx +23 -45
  135. package/src/components/auth/reset-password.tsx +14 -9
  136. package/src/components/{settings → auth/settings}/account/account-settings.tsx +15 -13
  137. package/src/components/{settings → auth/settings}/account/change-avatar.tsx +4 -5
  138. package/src/components/{settings → auth/settings}/account/change-email.tsx +5 -6
  139. package/src/components/auth/settings/account/user-profile.tsx +171 -0
  140. package/src/components/{settings → auth/settings}/security/active-session.tsx +8 -6
  141. package/src/components/{settings → auth/settings}/security/active-sessions.tsx +5 -10
  142. package/src/components/{settings → auth/settings}/security/change-password.tsx +22 -14
  143. package/src/components/{settings → auth/settings}/security/linked-account.tsx +10 -16
  144. package/src/components/{settings → auth/settings}/security/linked-accounts.tsx +4 -9
  145. package/src/components/{settings → auth/settings}/security/security-settings.tsx +7 -6
  146. package/src/components/{settings → auth/settings}/settings.tsx +2 -2
  147. package/src/components/auth/sign-in.tsx +39 -80
  148. package/src/components/auth/sign-out.tsx +2 -2
  149. package/src/components/auth/sign-up.tsx +110 -147
  150. package/src/components/{settings/account → auth/theme}/appearance.tsx +18 -25
  151. package/src/components/auth/theme/theme-toggle-item.tsx +110 -0
  152. package/src/components/{user → auth/user}/user-avatar.tsx +12 -4
  153. package/src/components/{user → auth/user}/user-button.tsx +15 -88
  154. package/src/components/{user → auth/user}/user-view.tsx +12 -4
  155. package/src/components/auth/username/sign-in-username.tsx +283 -0
  156. package/src/components/auth/username/username-field.tsx +122 -0
  157. package/src/email.ts +9 -0
  158. package/src/index.tsx +13 -27
  159. package/src/lib/auth/auth-plugin.ts +67 -0
  160. package/src/lib/auth/delete-user-plugin.ts +15 -0
  161. package/src/lib/auth/magic-link-plugin.ts +26 -0
  162. package/src/lib/auth/multi-session-plugin.ts +17 -0
  163. package/src/lib/auth/passkey-plugin.ts +17 -0
  164. package/src/lib/auth/theme-plugin.ts +86 -0
  165. package/src/lib/auth/username-plugin.tsx +30 -0
  166. package/src/plugins.ts +23 -0
  167. package/dist/components/auth/magic-link-button.d.ts +0 -13
  168. package/dist/components/auth/magic-link-button.js +0 -16
  169. package/dist/components/auth/magic-link.d.ts +0 -17
  170. package/dist/components/auth/magic-link.js +0 -111
  171. package/dist/components/auth/passkey-button.d.ts +0 -4
  172. package/dist/components/auth/passkey-button.js +0 -24
  173. package/dist/components/email/magic-link-email.d.ts +0 -3
  174. package/dist/components/email/new-device-email.d.ts +0 -3
  175. package/dist/components/email/otp-email.d.ts +0 -3
  176. package/dist/components/settings/account/account-settings.js +0 -23
  177. package/dist/components/settings/account/appearance.js +0 -71
  178. package/dist/components/settings/account/change-avatar.js +0 -89
  179. package/dist/components/settings/account/manage-account.js +0 -51
  180. package/dist/components/settings/account/manage-accounts.js +0 -33
  181. package/dist/components/settings/account/user-profile.js +0 -106
  182. package/dist/components/settings/security/active-session.js +0 -62
  183. package/dist/components/settings/security/active-sessions.js +0 -34
  184. package/dist/components/settings/security/change-password.js +0 -192
  185. package/dist/components/settings/security/delete-user.js +0 -97
  186. package/dist/components/settings/security/linked-account.js +0 -62
  187. package/dist/components/settings/security/linked-accounts.js +0 -45
  188. package/dist/components/settings/security/passkey.js +0 -43
  189. package/dist/components/settings/security/passkeys.js +0 -53
  190. package/dist/components/settings/security/security-settings.js +0 -25
  191. package/dist/components/settings/settings.js +0 -45
  192. package/dist/components/user/switch-account-item.js +0 -20
  193. package/dist/components/user/switch-account-menu.js +0 -28
  194. package/dist/components/user/user-avatar.js +0 -29
  195. package/dist/components/user/user-button.js +0 -91
  196. package/dist/components/user/user-view.js +0 -37
  197. package/dist/core.d.ts +0 -1
  198. package/dist/core.js +0 -1
  199. package/dist/react-exports.d.ts +0 -1
  200. package/dist/react-exports.js +0 -1
  201. package/src/components/auth/magic-link-button.tsx +0 -43
  202. package/src/components/auth/passkey-button.tsx +0 -36
  203. package/src/components/settings/account/user-profile.tsx +0 -218
  204. package/src/components/settings/security/passkeys.tsx +0 -104
  205. package/src/core.ts +0 -1
  206. package/src/react-exports.ts +0 -1
  207. /package/dist/components/{settings/security → auth/passkey}/passkey.d.ts +0 -0
  208. /package/dist/components/{settings → auth/settings}/account/change-avatar.d.ts +0 -0
  209. /package/dist/components/{settings → auth/settings}/security/active-session.d.ts +0 -0
  210. /package/dist/components/{settings → auth/settings}/security/linked-account.d.ts +0 -0
  211. /package/dist/components/{settings → auth/settings}/settings.d.ts +0 -0
  212. /package/dist/components/{user → auth/user}/user-avatar.d.ts +0 -0
  213. /package/dist/components/{user → auth/user}/user-view.d.ts +0 -0
@@ -1,89 +0,0 @@
1
- import { UserAvatar as e } from "../../user/user-avatar.js";
2
- import { useAuth as t, useSession as n, useUpdateUser as r } from "@better-auth-ui/react";
3
- import { Button as i, Dropdown as a, Label as o, Spinner as s, cn as c, toast as l } from "@heroui/react";
4
- import { jsx as u, jsxs as d } from "react/jsx-runtime";
5
- import { useRef as f, useState as p } from "react";
6
- import { CloudArrowUpIn as m, TrashBin as h } from "@gravity-ui/icons";
7
- import { fileToBase64 as g } from "@better-auth-ui/core";
8
- //#region src/components/settings/account/change-avatar.tsx
9
- function _({ className: _ }) {
10
- let { localization: v, avatar: y } = t(), { data: b } = n(), { mutate: x, isPending: S } = r({ onError: (e) => l.danger(e.error?.message || e.message) }), C = f(null), [w, T] = p(!1), [E, D] = p(!1), O = S || w || E;
11
- async function k(e) {
12
- let t = e.target.files?.[0];
13
- if (t) {
14
- e.target.value = "", T(!0);
15
- try {
16
- let e = await y.resize?.(t, y.size, y.extension) || t;
17
- x({ image: await y.upload?.(e) || await g(e) }, { onSuccess: () => l.success(v.settings.avatarChangedSuccess) });
18
- } catch (e) {
19
- e instanceof Error && l.danger(e.message);
20
- }
21
- T(!1);
22
- }
23
- }
24
- async function A() {
25
- let e = b?.user.image;
26
- x({ image: null }, { onSuccess: async () => {
27
- if (e) {
28
- D(!0);
29
- try {
30
- await y.delete?.(e);
31
- } finally {
32
- D(!1);
33
- }
34
- }
35
- l.success(v.settings.avatarDeletedSuccess);
36
- } });
37
- }
38
- return /* @__PURE__ */ d("div", {
39
- className: c("flex flex-col gap-1", _),
40
- children: [
41
- /* @__PURE__ */ u(o, {
42
- isDisabled: !b,
43
- children: v.settings.avatar
44
- }),
45
- /* @__PURE__ */ u("input", {
46
- ref: C,
47
- type: "file",
48
- accept: "image/*",
49
- className: "hidden",
50
- onChange: k
51
- }),
52
- /* @__PURE__ */ d("div", {
53
- className: "flex items-center gap-4",
54
- children: [/* @__PURE__ */ u(i, {
55
- type: "button",
56
- isIconOnly: !0,
57
- variant: "ghost",
58
- className: "p-0 h-auto w-auto rounded-full",
59
- isDisabled: !b || O,
60
- onPress: () => C.current?.click(),
61
- children: /* @__PURE__ */ u(e, {
62
- size: "lg",
63
- isPending: O
64
- })
65
- }), /* @__PURE__ */ d(a, { children: [/* @__PURE__ */ d(i, {
66
- isDisabled: !b || O,
67
- size: "sm",
68
- variant: "secondary",
69
- children: [O && /* @__PURE__ */ u(s, { size: "sm" }), v.settings.changeAvatar]
70
- }), /* @__PURE__ */ u(a.Popover, {
71
- className: "min-w-fit",
72
- children: /* @__PURE__ */ d(a.Menu, { children: [/* @__PURE__ */ d(a.Item, {
73
- textValue: v.settings.uploadAvatar,
74
- onAction: () => C.current?.click(),
75
- children: [/* @__PURE__ */ u(m, { className: "text-muted" }), /* @__PURE__ */ u(o, { children: v.settings.uploadAvatar })]
76
- }), /* @__PURE__ */ d(a.Item, {
77
- textValue: v.settings.deleteAvatar,
78
- isDisabled: !b?.user.image,
79
- onAction: A,
80
- variant: "danger",
81
- children: [/* @__PURE__ */ u(h, { className: "text-danger" }), /* @__PURE__ */ u(o, { children: v.settings.deleteAvatar })]
82
- })] })
83
- })] })]
84
- })
85
- ]
86
- });
87
- }
88
- //#endregion
89
- export { _ as ChangeAvatar };
@@ -1,51 +0,0 @@
1
- import { UserView as e } from "../../user/user-view.js";
2
- import { useAuth as t, useRevokeMultiSession as n, useSetActiveSession as r, useUser as i } from "@better-auth-ui/react";
3
- import { Button as a, Dropdown as o, Spinner as s, toast as c } from "@heroui/react";
4
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
5
- import { ArrowRightArrowLeft as d, ArrowRightFromSquare as f, Ellipsis as p } from "@gravity-ui/icons";
6
- //#region src/components/settings/account/manage-account.tsx
7
- function m({ deviceSession: m, isPending: h }) {
8
- let { localization: g } = t(), { data: _ } = i(), { mutate: v, isPending: y } = r({ onError: (e) => c.danger(e.error?.message || e.message) }), { mutate: b, isPending: x } = n({
9
- onError: (e) => c.danger(e.error?.message || e.message),
10
- onSuccess: () => c.success(g.settings.revokeSessionSuccess)
11
- }), S = m?.session.userId === _?.id, C = y || x;
12
- return /* @__PURE__ */ u("div", {
13
- className: "flex items-center justify-between gap-3",
14
- children: [
15
- /* @__PURE__ */ l(e, {
16
- user: m?.user,
17
- isPending: h,
18
- size: "md"
19
- }),
20
- m && S && /* @__PURE__ */ u(a, {
21
- className: "shrink-0",
22
- variant: "outline",
23
- size: "sm",
24
- onPress: () => b({ sessionToken: m.session.token }),
25
- isDisabled: C,
26
- children: [x ? /* @__PURE__ */ l(s, {
27
- color: "current",
28
- size: "sm"
29
- }) : /* @__PURE__ */ l(f, {}), g.auth.signOut]
30
- }),
31
- m && !S && /* @__PURE__ */ u(o, { children: [/* @__PURE__ */ l(a, {
32
- isIconOnly: !0,
33
- variant: "ghost",
34
- className: "shrink-0",
35
- size: "sm",
36
- isDisabled: C,
37
- children: /* @__PURE__ */ l(p, {})
38
- }), /* @__PURE__ */ l(o.Popover, { children: /* @__PURE__ */ u(o.Menu, { children: [/* @__PURE__ */ u(o.Item, {
39
- textValue: g.auth.switchAccount,
40
- onAction: () => v({ sessionToken: m.session.token }),
41
- children: [/* @__PURE__ */ l(d, { className: "text-muted" }), g.auth.switchAccount]
42
- }), /* @__PURE__ */ u(o.Item, {
43
- textValue: g.auth.signOut,
44
- onAction: () => b({ sessionToken: m.session.token }),
45
- children: [/* @__PURE__ */ l(f, { className: "text-muted" }), g.auth.signOut]
46
- })] }) })] })
47
- ]
48
- });
49
- }
50
- //#endregion
51
- export { m as ManageAccount };
@@ -1,33 +0,0 @@
1
- import { ManageAccount as e } from "./manage-account.js";
2
- import { useAuth as t, useListDeviceSessions as n, useSession as r } from "@better-auth-ui/react";
3
- import { Card as i, cn as a, toast as o } from "@heroui/react";
4
- import { jsx as s, jsxs as c } from "react/jsx-runtime";
5
- //#region src/components/settings/account/manage-accounts.tsx
6
- function l({ className: l, variant: u, ...d }) {
7
- let { localization: f } = t(), { data: p } = r(), { data: m, isPending: h } = n({ throwOnError: (e) => (e.error && o.danger(e.error.message), !1) }), g = m?.filter((e) => e.session.id !== p?.session.id), _ = [{
8
- key: "current",
9
- deviceSession: h ? null : p,
10
- isPending: h
11
- }, ...g?.map((e) => ({
12
- key: e.session.id,
13
- deviceSession: e,
14
- isPending: !1
15
- })) ?? []];
16
- return /* @__PURE__ */ c("div", { children: [/* @__PURE__ */ s("h2", {
17
- className: a("text-sm font-semibold mb-3"),
18
- children: f.settings.manageAccounts
19
- }), /* @__PURE__ */ s(i, {
20
- className: a(l),
21
- variant: u,
22
- ...d,
23
- children: /* @__PURE__ */ s(i.Content, {
24
- className: "gap-0",
25
- children: _.map((t, n) => /* @__PURE__ */ c("div", { children: [n > 0 && /* @__PURE__ */ s("div", { className: "border-b border-dashed -mx-4 md:-mx-6 my-4" }), /* @__PURE__ */ s(e, {
26
- deviceSession: t.deviceSession,
27
- isPending: t.isPending
28
- })] }, t.key))
29
- })
30
- })] });
31
- }
32
- //#endregion
33
- export { l as ManageAccounts };
@@ -1,106 +0,0 @@
1
- import { ChangeAvatar as e } from "./change-avatar.js";
2
- import { useAuth as t, useIsUsernameAvailable as n, useSession as r, useUpdateUser as i } from "@better-auth-ui/react";
3
- import { Button as a, Card as o, FieldError as s, Fieldset as c, Form as l, Input as u, InputGroup as d, Label as f, Skeleton as p, Spinner as m, TextField as h, cn as g, toast as _ } from "@heroui/react";
4
- import { jsx as v, jsxs as y } from "react/jsx-runtime";
5
- import { useEffect as b, useState as x } from "react";
6
- import { Check as S, Xmark as C } from "@gravity-ui/icons";
7
- import { useDebouncer as w } from "@tanstack/react-pacer";
8
- //#region src/components/settings/account/user-profile.tsx
9
- function T({ className: T, variant: E, ...D }) {
10
- let { localization: O, username: k } = t(), { data: A } = r(), j = (k?.displayUsername ? A?.user?.displayUsername : A?.user?.username) || "", [M, N] = x(j);
11
- b(() => {
12
- N(j);
13
- }, [j]);
14
- let { mutate: P, data: F, error: I, reset: L } = n(), R = w((e) => {
15
- if (!e.trim() || e.trim() === j) {
16
- L();
17
- return;
18
- }
19
- P({ username: e.trim() });
20
- }, { wait: 500 });
21
- function z(e) {
22
- N(e), L(), k?.isUsernameAvailable && R.maybeExecute(e);
23
- }
24
- let { mutate: B, isPending: V } = i({
25
- onError: (e) => _.danger(e.error?.message || e.message),
26
- onSuccess: () => _.success(O.settings.profileUpdatedSuccess)
27
- });
28
- function H(e) {
29
- e.preventDefault(), B({
30
- name: new FormData(e.currentTarget).get("name"),
31
- ...k?.enabled ? {
32
- username: M.trim(),
33
- ...k.displayUsername ? { displayUsername: M.trim() } : {}
34
- } : {}
35
- });
36
- }
37
- return /* @__PURE__ */ y("div", { children: [/* @__PURE__ */ v("h2", {
38
- className: g("text-sm font-semibold mb-3"),
39
- children: O.settings.profile
40
- }), /* @__PURE__ */ v(o, {
41
- className: g("p-4 gap-4", T),
42
- variant: E,
43
- ...D,
44
- children: /* @__PURE__ */ v(o.Content, { children: /* @__PURE__ */ v(l, {
45
- onSubmit: H,
46
- children: /* @__PURE__ */ y(c, {
47
- className: "w-full gap-4",
48
- children: [
49
- /* @__PURE__ */ v(e, {}),
50
- /* @__PURE__ */ y(c.Group, { children: [k?.enabled && /* @__PURE__ */ y(h, {
51
- type: "text",
52
- autoComplete: "username",
53
- minLength: k.minUsernameLength,
54
- maxLength: k.maxUsernameLength,
55
- isDisabled: V || !A,
56
- value: M,
57
- onChange: z,
58
- isInvalid: !!I || F && !F.available,
59
- children: [
60
- /* @__PURE__ */ v(f, { children: O.auth.username }),
61
- A ? /* @__PURE__ */ y(d, {
62
- variant: E === "transparent" ? "primary" : "secondary",
63
- children: [/* @__PURE__ */ v(d.Input, {
64
- placeholder: O.auth.usernamePlaceholder,
65
- name: "username"
66
- }), k.isUsernameAvailable && M.trim() && M.trim() !== j && /* @__PURE__ */ v(d.Suffix, {
67
- className: "px-2",
68
- children: F?.available ? /* @__PURE__ */ v(S, { className: "text-success" }) : I || F?.available === !1 ? /* @__PURE__ */ v(C, { className: "text-danger" }) : /* @__PURE__ */ v(m, {
69
- size: "sm",
70
- color: "current"
71
- })
72
- })]
73
- }) : /* @__PURE__ */ v(p, { className: "h-10 md:h-9 w-full rounded-xl" }),
74
- /* @__PURE__ */ v(s, { children: I?.error?.message || I?.message || F?.available === !1 && O.auth.usernameTaken })
75
- ]
76
- }), /* @__PURE__ */ y(h, {
77
- name: "name",
78
- defaultValue: A?.user.name,
79
- isDisabled: V || !A,
80
- children: [
81
- /* @__PURE__ */ v(f, { children: O.auth.name }),
82
- A ? /* @__PURE__ */ v(u, {
83
- autoComplete: "name",
84
- placeholder: O.auth.name,
85
- variant: E === "transparent" ? "primary" : "secondary"
86
- }) : /* @__PURE__ */ v(p, { className: "h-10 md:h-9 w-full rounded-xl" }),
87
- /* @__PURE__ */ v(s, {})
88
- ]
89
- }, A?.user?.name)] }),
90
- /* @__PURE__ */ v(c.Actions, { children: /* @__PURE__ */ y(a, {
91
- type: "submit",
92
- isPending: V,
93
- isDisabled: !A,
94
- size: "sm",
95
- children: [V && /* @__PURE__ */ v(m, {
96
- color: "current",
97
- size: "sm"
98
- }), O.settings.saveChanges]
99
- }) })
100
- ]
101
- })
102
- }) })
103
- })] });
104
- }
105
- //#endregion
106
- export { T as UserProfile };
@@ -1,62 +0,0 @@
1
- import { useAuth as e, useRevokeSession as t, useSession as n } from "@better-auth-ui/react";
2
- import { Button as r, Chip as i, Spinner as a, toast as o } from "@heroui/react";
3
- import { jsx as s, jsxs as c } from "react/jsx-runtime";
4
- import { ArrowRightFromSquare as l, Display as u, Smartphone as d, Xmark as f } from "@gravity-ui/icons";
5
- import p from "bowser";
6
- //#region src/components/settings/security/active-session.tsx
7
- function m(e) {
8
- let t = Math.floor((Date.now() - e.getTime()) / 1e3), n = new Intl.RelativeTimeFormat(void 0, { numeric: "auto" });
9
- for (let [e, r] of [
10
- ["year", 31536e3],
11
- ["month", 2592e3],
12
- ["week", 604800],
13
- ["day", 86400],
14
- ["hour", 3600],
15
- ["minute", 60],
16
- ["second", 1]
17
- ]) if (t >= r) return n.format(-Math.floor(t / r), e);
18
- return n.format(0, "second");
19
- }
20
- function h({ activeSession: h }) {
21
- let { basePaths: g, localization: _, viewPaths: v, navigate: y } = e(), { data: b } = n({ refetchOnMount: !1 }), { mutate: x, isPending: S } = t({
22
- onError: (e) => o.danger(e.error?.message || e.message),
23
- onSuccess: () => o.success(_.settings.revokeSessionSuccess)
24
- }), C = h.token === b?.session.token, w = p.parse(h.userAgent || "");
25
- return /* @__PURE__ */ c("div", {
26
- className: "flex items-center gap-3",
27
- children: [
28
- /* @__PURE__ */ s("div", {
29
- className: "flex size-10 shrink-0 items-center justify-center rounded-xl bg-surface-secondary",
30
- children: w.platform.type === "mobile" || w.platform.type === "tablet" ? /* @__PURE__ */ s(d, { className: "size-4.5" }) : /* @__PURE__ */ s(u, { className: "size-4.5" })
31
- }),
32
- /* @__PURE__ */ c("div", {
33
- className: "flex flex-col min-w-0",
34
- children: [/* @__PURE__ */ c("span", {
35
- className: "text-sm font-medium truncate",
36
- children: [w.browser.name || "Unknown Browser", w.os.name ? `, ${w.os.name}` : ""]
37
- }), C ? /* @__PURE__ */ s(i, {
38
- color: "accent",
39
- size: "sm",
40
- children: _.settings.currentSession
41
- }) : h.createdAt && /* @__PURE__ */ s("span", {
42
- className: "text-xs text-muted capitalize",
43
- children: m(h.createdAt)
44
- })]
45
- }),
46
- /* @__PURE__ */ c(r, {
47
- className: "ml-auto shrink-0",
48
- variant: "outline",
49
- size: "sm",
50
- onPress: () => C ? y({ to: `${g.auth}/${v.auth.signOut}` }) : x(h),
51
- isPending: S,
52
- "aria-label": C ? _.auth.signOut : _.settings.revokeSession,
53
- children: [S ? /* @__PURE__ */ s(a, {
54
- color: "current",
55
- size: "sm"
56
- }) : s(C ? l : f, {}), C ? _.auth.signOut : _.settings.revoke]
57
- })
58
- ]
59
- });
60
- }
61
- //#endregion
62
- export { h as ActiveSession };
@@ -1,34 +0,0 @@
1
- import { ActiveSession as e } from "./active-session.js";
2
- import { useAuth as t, useListSessions as n, useSession as r } from "@better-auth-ui/react";
3
- import { Card as i, Skeleton as a, cn as o, toast as s } from "@heroui/react";
4
- import { jsx as c, jsxs as l } from "react/jsx-runtime";
5
- //#region src/components/settings/security/active-sessions.tsx
6
- function u({ className: a, variant: u, ...f }) {
7
- let { localization: p } = t(), { data: m } = r(), { data: h, isPending: g } = n({ throwOnError: (e) => (e.error && s.danger(e.error.message), !1) }), _ = h?.toSorted((e) => e.id === m?.session.id ? -1 : 1);
8
- return /* @__PURE__ */ l("div", { children: [/* @__PURE__ */ c("h2", {
9
- className: o("text-sm font-semibold mb-3"),
10
- children: p.settings.activeSessions
11
- }), /* @__PURE__ */ c(i, {
12
- className: o(a),
13
- variant: u,
14
- ...f,
15
- children: /* @__PURE__ */ c(i.Content, {
16
- className: "gap-0",
17
- children: g ? /* @__PURE__ */ c(d, {}) : _?.map((t, n) => /* @__PURE__ */ l("div", { children: [n > 0 && /* @__PURE__ */ c("div", { className: "border-b border-dashed -mx-4 md:-mx-6 my-4" }), /* @__PURE__ */ c(e, { activeSession: t })] }, t.id))
18
- })
19
- })] });
20
- }
21
- function d() {
22
- return /* @__PURE__ */ c("div", {
23
- className: "flex items-center justify-between",
24
- children: /* @__PURE__ */ l("div", {
25
- className: "flex items-center gap-3",
26
- children: [/* @__PURE__ */ c(a, { className: "size-10 rounded-xl" }), /* @__PURE__ */ l("div", {
27
- className: "flex flex-col gap-1",
28
- children: [/* @__PURE__ */ c(a, { className: "h-4 w-32 rounded-lg" }), /* @__PURE__ */ c(a, { className: "h-3 w-24 rounded-lg" })]
29
- })]
30
- })
31
- });
32
- }
33
- //#endregion
34
- export { u as ActiveSessions };
@@ -1,192 +0,0 @@
1
- import { useAuth as e, useChangePassword as t, useListAccounts as n, useRequestPasswordReset as r, useSession as i } from "@better-auth-ui/react";
2
- import { Button as a, Card as o, FieldError as s, Fieldset as c, Form as l, Input as u, InputGroup as d, Label as f, Skeleton as p, Spinner as m, TextField as h, cn as g, toast as _ } from "@heroui/react";
3
- import { jsx as v, jsxs as y } from "react/jsx-runtime";
4
- import { useState as b } from "react";
5
- import { Eye as x, EyeSlash as S } from "@gravity-ui/icons";
6
- //#region src/components/settings/security/change-password.tsx
7
- function C({ className: t, variant: r, ...a }) {
8
- let { emailAndPassword: o, localization: s } = e(), { data: c } = i(), { data: l, isPending: u } = n(), d = l?.some((e) => e.providerId === "credential");
9
- return !u && !d ? /* @__PURE__ */ v(w, {
10
- className: t,
11
- variant: r,
12
- ...a
13
- }) : /* @__PURE__ */ v(T, {
14
- className: t,
15
- variant: r,
16
- emailAndPassword: o,
17
- localization: s,
18
- session: u ? void 0 : c,
19
- ...a
20
- });
21
- }
22
- function w({ className: t, variant: n, ...s }) {
23
- let { localization: c } = e(), { data: l } = i(), { mutate: u, isPending: d } = r({
24
- onError: (e) => _.danger(e.error?.message || e.message),
25
- onSuccess: () => _.success(c.auth.passwordResetEmailSent)
26
- }), f = () => {
27
- l?.user.email && u({ email: l.user.email });
28
- };
29
- return /* @__PURE__ */ y("div", { children: [/* @__PURE__ */ v("h2", {
30
- className: g("text-sm font-semibold mb-3"),
31
- children: c.settings.changePassword
32
- }), /* @__PURE__ */ v(o, {
33
- className: g(t),
34
- variant: n,
35
- ...s,
36
- children: /* @__PURE__ */ y(o.Content, {
37
- className: "flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",
38
- children: [/* @__PURE__ */ y("div", { children: [/* @__PURE__ */ v("p", {
39
- className: "text-sm font-medium leading-tight",
40
- children: c.settings.setPassword
41
- }), /* @__PURE__ */ v("p", {
42
- className: "text-muted text-xs mt-0.5",
43
- children: c.settings.setPasswordDescription
44
- })] }), /* @__PURE__ */ y(a, {
45
- size: "sm",
46
- isPending: d,
47
- isDisabled: !l,
48
- onPress: f,
49
- children: [d && /* @__PURE__ */ v(m, {
50
- color: "current",
51
- size: "sm"
52
- }), c.auth.sendResetLink]
53
- })]
54
- })
55
- })] });
56
- }
57
- function T({ className: e, variant: n, emailAndPassword: r, localization: i, session: C, ...w }) {
58
- let [T, E] = b(""), [D, O] = b(""), [k, A] = b(""), { mutate: j, isPending: M } = t({
59
- onError: (e) => {
60
- E(""), O(""), A(""), _.danger(e.error?.message || e.message);
61
- },
62
- onSuccess: () => {
63
- E(""), O(""), A(""), _.success(i.settings.changePasswordSuccess);
64
- }
65
- }), [N, P] = b(!1), [F, I] = b(!1), L = (e) => {
66
- if (e.preventDefault(), r?.confirmPassword && D !== k) {
67
- E(""), O(""), A(""), _.danger(i.auth.passwordsDoNotMatch);
68
- return;
69
- }
70
- j({
71
- currentPassword: T,
72
- newPassword: D,
73
- revokeOtherSessions: !0
74
- });
75
- };
76
- return /* @__PURE__ */ y("div", { children: [/* @__PURE__ */ v("h2", {
77
- className: g("text-sm font-semibold mb-3"),
78
- children: i.settings.changePassword
79
- }), /* @__PURE__ */ v(o, {
80
- className: g("p-4 gap-4", e),
81
- variant: n,
82
- ...w,
83
- children: /* @__PURE__ */ v(o.Content, { children: /* @__PURE__ */ v(l, {
84
- onSubmit: L,
85
- children: /* @__PURE__ */ y(c, {
86
- className: "w-full gap-4",
87
- children: [/* @__PURE__ */ y(c.Group, { children: [
88
- /* @__PURE__ */ y(h, {
89
- name: "currentPassword",
90
- type: "password",
91
- isDisabled: M || !C,
92
- defaultValue: "",
93
- value: T,
94
- onChange: E,
95
- children: [
96
- /* @__PURE__ */ v(f, { children: i.settings.currentPassword }),
97
- /* @__PURE__ */ v(u, {
98
- className: g(!C && "hidden"),
99
- autoComplete: "current-password",
100
- placeholder: i.settings.currentPasswordPlaceholder,
101
- required: !0,
102
- variant: n === "transparent" ? "primary" : "secondary"
103
- }),
104
- !C && /* @__PURE__ */ v(p, { className: "h-10 md:h-9 w-full rounded-xl" }),
105
- /* @__PURE__ */ v(s, {})
106
- ]
107
- }),
108
- /* @__PURE__ */ y(h, {
109
- minLength: r?.minPasswordLength,
110
- maxLength: r?.maxPasswordLength,
111
- isDisabled: M || !C,
112
- value: D,
113
- onChange: O,
114
- children: [
115
- /* @__PURE__ */ v(f, { children: i.auth.newPassword }),
116
- /* @__PURE__ */ y(d, {
117
- className: g(!C && "hidden"),
118
- variant: n === "transparent" ? "primary" : "secondary",
119
- children: [/* @__PURE__ */ v(d.Input, {
120
- name: "newPassword",
121
- type: N ? "text" : "password",
122
- autoComplete: "new-password",
123
- placeholder: i.auth.newPasswordPlaceholder,
124
- required: !0
125
- }), /* @__PURE__ */ v(d.Suffix, {
126
- className: "px-0",
127
- children: /* @__PURE__ */ v(a, {
128
- isIconOnly: !0,
129
- "aria-label": N ? i.auth.hidePassword : i.auth.showPassword,
130
- size: "sm",
131
- variant: "ghost",
132
- onPress: () => P(!N),
133
- isDisabled: M,
134
- children: v(N ? S : x, {})
135
- })
136
- })]
137
- }),
138
- !C && /* @__PURE__ */ v(p, { className: "h-10 md:h-9 w-full rounded-xl" }),
139
- /* @__PURE__ */ v(s, {})
140
- ]
141
- }),
142
- r?.confirmPassword && /* @__PURE__ */ y(h, {
143
- minLength: r?.minPasswordLength,
144
- maxLength: r?.maxPasswordLength,
145
- isDisabled: M || !C,
146
- isRequired: !0,
147
- value: k,
148
- onChange: A,
149
- children: [
150
- /* @__PURE__ */ v(f, { children: i.auth.confirmPassword }),
151
- /* @__PURE__ */ y(d, {
152
- className: g(!C && "hidden"),
153
- variant: n === "transparent" ? "primary" : "secondary",
154
- children: [/* @__PURE__ */ v(d.Input, {
155
- name: "confirmPassword",
156
- type: F ? "text" : "password",
157
- autoComplete: "new-password",
158
- placeholder: i.auth.confirmPasswordPlaceholder,
159
- required: !0
160
- }), /* @__PURE__ */ v(d.Suffix, {
161
- className: "px-0",
162
- children: /* @__PURE__ */ v(a, {
163
- isIconOnly: !0,
164
- "aria-label": F ? i.auth.hidePassword : i.auth.showPassword,
165
- size: "sm",
166
- variant: "ghost",
167
- onPress: () => I(!F),
168
- isDisabled: M,
169
- children: v(F ? S : x, {})
170
- })
171
- })]
172
- }),
173
- !C && /* @__PURE__ */ v(p, { className: "h-10 md:h-9 w-full rounded-xl" }),
174
- /* @__PURE__ */ v(s, {})
175
- ]
176
- })
177
- ] }), /* @__PURE__ */ v(c.Actions, { children: /* @__PURE__ */ y(a, {
178
- type: "submit",
179
- isPending: M,
180
- isDisabled: !C,
181
- size: "sm",
182
- children: [M && /* @__PURE__ */ v(m, {
183
- color: "current",
184
- size: "sm"
185
- }), i.settings.updatePassword]
186
- }) })]
187
- })
188
- }) })
189
- })] });
190
- }
191
- //#endregion
192
- export { C as ChangePassword };
@@ -1,97 +0,0 @@
1
- import { useAuth as e, useDeleteUser as t, useListAccounts as n } from "@better-auth-ui/react";
2
- import { AlertDialog as r, Button as i, Card as a, FieldError as o, Form as s, Input as c, Label as l, Spinner as u, TextField as d, cn as f, toast as p } from "@heroui/react";
3
- import { jsx as m, jsxs as h } from "react/jsx-runtime";
4
- import { useState as g } from "react";
5
- import { TriangleExclamation as _ } from "@gravity-ui/icons";
6
- //#region src/components/settings/security/delete-user.tsx
7
- function v({ className: v, variant: y, ...b }) {
8
- let { basePaths: x, deleteUser: S, localization: C, navigate: w, viewPaths: T } = e(), { data: E } = n(), [D, O] = g(!1), [k, A] = g(""), j = E?.some((e) => e.providerId === "credential"), M = !S?.sendDeleteAccountVerification && j, { mutate: N, isPending: P } = t(), F = (e) => {
9
- O(e), A("");
10
- }, I = async (e) => {
11
- e.preventDefault(), N({ ...M ? { password: k } : {} }, {
12
- onSuccess: () => {
13
- O(!1), A(""), S?.sendDeleteAccountVerification ? p.success(C.settings.deleteUserVerificationSent) : (p.success(C.settings.deleteUserSuccess), w({
14
- to: `${x.auth}/${T.auth.signIn}`,
15
- replace: !0
16
- }));
17
- },
18
- onError: (e) => {
19
- p.danger(e.error?.message || e.message);
20
- }
21
- });
22
- };
23
- return /* @__PURE__ */ m(a, {
24
- className: f("border border-danger", v),
25
- variant: y,
26
- ...b,
27
- children: /* @__PURE__ */ h(a.Content, {
28
- className: "flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",
29
- children: [/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("p", {
30
- className: "text-sm font-medium leading-tight",
31
- children: C.settings.deleteUser
32
- }), /* @__PURE__ */ m("p", {
33
- className: "text-muted text-xs mt-0.5",
34
- children: C.settings.deleteUserDescription
35
- })] }), /* @__PURE__ */ h(r, { children: [/* @__PURE__ */ m(i, {
36
- isDisabled: !E,
37
- size: "sm",
38
- variant: "danger",
39
- onPress: () => O(!0),
40
- children: C.settings.deleteUser
41
- }), /* @__PURE__ */ m(r.Backdrop, {
42
- isOpen: D,
43
- onOpenChange: F,
44
- children: /* @__PURE__ */ m(r.Container, { children: /* @__PURE__ */ m(r.Dialog, { children: /* @__PURE__ */ h(s, {
45
- onSubmit: I,
46
- children: [
47
- /* @__PURE__ */ m(r.CloseTrigger, {}),
48
- /* @__PURE__ */ h(r.Header, { children: [/* @__PURE__ */ m(r.Icon, {
49
- status: "danger",
50
- children: /* @__PURE__ */ m(_, {})
51
- }), /* @__PURE__ */ m(r.Heading, { children: C.settings.deleteUser })] }),
52
- /* @__PURE__ */ h(r.Body, {
53
- className: "overflow-visible",
54
- children: [/* @__PURE__ */ m("p", {
55
- className: "text-muted text-sm",
56
- children: C.settings.deleteUserDescription
57
- }), M && /* @__PURE__ */ h(d, {
58
- className: "mt-4",
59
- name: "password",
60
- type: "password",
61
- isDisabled: P,
62
- value: k,
63
- onChange: A,
64
- children: [
65
- /* @__PURE__ */ m(l, { children: C.auth.password }),
66
- /* @__PURE__ */ m(c, {
67
- autoComplete: "current-password",
68
- placeholder: C.auth.passwordPlaceholder,
69
- required: !0,
70
- variant: "secondary"
71
- }),
72
- /* @__PURE__ */ m(o, {})
73
- ]
74
- })]
75
- }),
76
- /* @__PURE__ */ h(r.Footer, { children: [/* @__PURE__ */ m(i, {
77
- slot: "close",
78
- variant: "tertiary",
79
- isDisabled: P,
80
- children: C.settings.cancel
81
- }), /* @__PURE__ */ h(i, {
82
- type: "submit",
83
- variant: "danger",
84
- isPending: P,
85
- children: [P && /* @__PURE__ */ m(u, {
86
- color: "current",
87
- size: "sm"
88
- }), C.settings.deleteUser]
89
- })] })
90
- ]
91
- }) }) })
92
- })] })]
93
- })
94
- });
95
- }
96
- //#endregion
97
- export { v as DeleteUser };