@stackframe/stack 2.8.3 → 2.8.5

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 (122) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/components-page/account-settings/active-sessions/active-sessions-page.js +151 -0
  3. package/dist/components-page/account-settings/active-sessions/active-sessions-page.js.map +1 -0
  4. package/dist/components-page/account-settings/api-keys/api-keys-page.js +70 -0
  5. package/dist/components-page/account-settings/api-keys/api-keys-page.js.map +1 -0
  6. package/dist/components-page/account-settings/editable-text.js +75 -0
  7. package/dist/components-page/account-settings/editable-text.js.map +1 -0
  8. package/dist/components-page/account-settings/email-and-auth/email-and-auth-page.js +46 -0
  9. package/dist/components-page/account-settings/email-and-auth/email-and-auth-page.js.map +1 -0
  10. package/dist/components-page/account-settings/email-and-auth/emails-section.js +188 -0
  11. package/dist/components-page/account-settings/email-and-auth/emails-section.js.map +1 -0
  12. package/dist/components-page/account-settings/email-and-auth/mfa-section.js +146 -0
  13. package/dist/components-page/account-settings/email-and-auth/mfa-section.js.map +1 -0
  14. package/dist/components-page/account-settings/email-and-auth/otp-section.js +89 -0
  15. package/dist/components-page/account-settings/email-and-auth/otp-section.js.map +1 -0
  16. package/dist/components-page/account-settings/email-and-auth/passkey-section.js +92 -0
  17. package/dist/components-page/account-settings/email-and-auth/passkey-section.js.map +1 -0
  18. package/dist/components-page/account-settings/email-and-auth/password-section.js +181 -0
  19. package/dist/components-page/account-settings/email-and-auth/password-section.js.map +1 -0
  20. package/dist/components-page/account-settings/page-layout.js +34 -0
  21. package/dist/components-page/account-settings/page-layout.js.map +1 -0
  22. package/dist/components-page/account-settings/profile-page/profile-page.js +75 -0
  23. package/dist/components-page/account-settings/profile-page/profile-page.js.map +1 -0
  24. package/dist/components-page/account-settings/section.js +44 -0
  25. package/dist/components-page/account-settings/section.js.map +1 -0
  26. package/dist/components-page/account-settings/settings/delete-account-section.js +87 -0
  27. package/dist/components-page/account-settings/settings/delete-account-section.js.map +1 -0
  28. package/dist/components-page/account-settings/settings/settings-page.js +40 -0
  29. package/dist/components-page/account-settings/settings/settings-page.js.map +1 -0
  30. package/dist/components-page/account-settings/settings/sign-out-section.js +54 -0
  31. package/dist/components-page/account-settings/settings/sign-out-section.js.map +1 -0
  32. package/dist/components-page/account-settings/teams/leave-team-section.js +79 -0
  33. package/dist/components-page/account-settings/teams/leave-team-section.js.map +1 -0
  34. package/dist/components-page/account-settings/teams/team-api-keys-section.js +89 -0
  35. package/dist/components-page/account-settings/teams/team-api-keys-section.js.map +1 -0
  36. package/dist/components-page/account-settings/teams/team-creation-page.js +92 -0
  37. package/dist/components-page/account-settings/teams/team-creation-page.js.map +1 -0
  38. package/dist/components-page/account-settings/teams/team-display-name-section.js +57 -0
  39. package/dist/components-page/account-settings/teams/team-display-name-section.js.map +1 -0
  40. package/dist/components-page/account-settings/teams/team-member-invitation-section.js +131 -0
  41. package/dist/components-page/account-settings/teams/team-member-invitation-section.js.map +1 -0
  42. package/dist/components-page/account-settings/teams/team-member-list-section.js +61 -0
  43. package/dist/components-page/account-settings/teams/team-member-list-section.js.map +1 -0
  44. package/dist/components-page/account-settings/teams/team-page.js +50 -0
  45. package/dist/components-page/account-settings/teams/team-page.js.map +1 -0
  46. package/dist/components-page/account-settings/teams/team-profile-image-section.js +59 -0
  47. package/dist/components-page/account-settings/teams/team-profile-image-section.js.map +1 -0
  48. package/dist/components-page/account-settings/teams/team-profile-user-section.js +56 -0
  49. package/dist/components-page/account-settings/teams/team-profile-user-section.js.map +1 -0
  50. package/dist/components-page/account-settings.js +16 -1173
  51. package/dist/components-page/account-settings.js.map +1 -1
  52. package/dist/components-page/section.js +6 -0
  53. package/dist/components-page/section.js.map +1 -0
  54. package/dist/esm/components-page/account-settings/active-sessions/active-sessions-page.js +126 -0
  55. package/dist/esm/components-page/account-settings/active-sessions/active-sessions-page.js.map +1 -0
  56. package/dist/esm/components-page/account-settings/api-keys/api-keys-page.js +45 -0
  57. package/dist/esm/components-page/account-settings/api-keys/api-keys-page.js.map +1 -0
  58. package/dist/esm/components-page/account-settings/editable-text.js +50 -0
  59. package/dist/esm/components-page/account-settings/editable-text.js.map +1 -0
  60. package/dist/esm/components-page/account-settings/email-and-auth/email-and-auth-page.js +21 -0
  61. package/dist/esm/components-page/account-settings/email-and-auth/email-and-auth-page.js.map +1 -0
  62. package/dist/esm/components-page/account-settings/email-and-auth/emails-section.js +163 -0
  63. package/dist/esm/components-page/account-settings/email-and-auth/emails-section.js.map +1 -0
  64. package/dist/esm/components-page/account-settings/email-and-auth/mfa-section.js +111 -0
  65. package/dist/esm/components-page/account-settings/email-and-auth/mfa-section.js.map +1 -0
  66. package/dist/esm/components-page/account-settings/email-and-auth/otp-section.js +64 -0
  67. package/dist/esm/components-page/account-settings/email-and-auth/otp-section.js.map +1 -0
  68. package/dist/esm/components-page/account-settings/email-and-auth/passkey-section.js +67 -0
  69. package/dist/esm/components-page/account-settings/email-and-auth/passkey-section.js.map +1 -0
  70. package/dist/esm/components-page/account-settings/email-and-auth/password-section.js +146 -0
  71. package/dist/esm/components-page/account-settings/email-and-auth/password-section.js.map +1 -0
  72. package/dist/esm/components-page/account-settings/page-layout.js +9 -0
  73. package/dist/esm/components-page/account-settings/page-layout.js.map +1 -0
  74. package/dist/esm/components-page/account-settings/profile-page/profile-page.js +50 -0
  75. package/dist/esm/components-page/account-settings/profile-page/profile-page.js.map +1 -0
  76. package/dist/esm/components-page/account-settings/section.js +19 -0
  77. package/dist/esm/components-page/account-settings/section.js.map +1 -0
  78. package/dist/esm/components-page/account-settings/settings/delete-account-section.js +62 -0
  79. package/dist/esm/components-page/account-settings/settings/delete-account-section.js.map +1 -0
  80. package/dist/esm/components-page/account-settings/settings/settings-page.js +15 -0
  81. package/dist/esm/components-page/account-settings/settings/settings-page.js.map +1 -0
  82. package/dist/esm/components-page/account-settings/settings/sign-out-section.js +29 -0
  83. package/dist/esm/components-page/account-settings/settings/sign-out-section.js.map +1 -0
  84. package/dist/esm/components-page/account-settings/teams/leave-team-section.js +54 -0
  85. package/dist/esm/components-page/account-settings/teams/leave-team-section.js.map +1 -0
  86. package/dist/esm/components-page/account-settings/teams/team-api-keys-section.js +64 -0
  87. package/dist/esm/components-page/account-settings/teams/team-api-keys-section.js.map +1 -0
  88. package/dist/esm/components-page/account-settings/teams/team-creation-page.js +67 -0
  89. package/dist/esm/components-page/account-settings/teams/team-creation-page.js.map +1 -0
  90. package/dist/esm/components-page/account-settings/teams/team-display-name-section.js +32 -0
  91. package/dist/esm/components-page/account-settings/teams/team-display-name-section.js.map +1 -0
  92. package/dist/esm/components-page/account-settings/teams/team-member-invitation-section.js +106 -0
  93. package/dist/esm/components-page/account-settings/teams/team-member-invitation-section.js.map +1 -0
  94. package/dist/esm/components-page/account-settings/teams/team-member-list-section.js +36 -0
  95. package/dist/esm/components-page/account-settings/teams/team-member-list-section.js.map +1 -0
  96. package/dist/esm/components-page/account-settings/teams/team-page.js +25 -0
  97. package/dist/esm/components-page/account-settings/teams/team-page.js.map +1 -0
  98. package/dist/esm/components-page/account-settings/teams/team-profile-image-section.js +34 -0
  99. package/dist/esm/components-page/account-settings/teams/team-profile-image-section.js.map +1 -0
  100. package/dist/esm/components-page/account-settings/teams/team-profile-user-section.js +31 -0
  101. package/dist/esm/components-page/account-settings/teams/team-profile-user-section.js.map +1 -0
  102. package/dist/esm/components-page/account-settings.js +14 -1158
  103. package/dist/esm/components-page/account-settings.js.map +1 -1
  104. package/dist/esm/components-page/section.js +4 -0
  105. package/dist/esm/components-page/section.js.map +1 -0
  106. package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  107. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +79 -0
  108. package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  109. package/dist/esm/lib/stack-app/apps/implementations/common.js +1 -1
  110. package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
  111. package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  112. package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
  113. package/dist/index.d.mts +5 -1
  114. package/dist/index.d.ts +5 -1
  115. package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
  116. package/dist/lib/stack-app/apps/implementations/client-app-impl.js +79 -0
  117. package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
  118. package/dist/lib/stack-app/apps/implementations/common.js +1 -1
  119. package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
  120. package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
  121. package/dist/lib/stack-app/projects/index.js.map +1 -1
  122. package/package.json +4 -4
@@ -2,33 +2,22 @@
2
2
  "use client";
3
3
 
4
4
  // src/components-page/account-settings.tsx
5
- import { yupResolver } from "@hookform/resolvers/yup";
6
- import { createTOTPKeyURI, verifyTOTP } from "@oslojs/otp";
7
- import { KnownErrors } from "@stackframe/stack-shared";
8
- import { getPasswordError } from "@stackframe/stack-shared/dist/helpers/password";
9
- import { useAsyncCallback } from "@stackframe/stack-shared/dist/hooks/use-async-callback";
10
- import { passwordSchema as schemaFieldsPasswordSchema, strictEmailSchema, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields";
11
- import { generateRandomValues } from "@stackframe/stack-shared/dist/utils/crypto";
12
- import { fromNow } from "@stackframe/stack-shared/dist/utils/dates";
13
- import { StackAssertionError, captureError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
14
- import { runAsynchronously, runAsynchronouslyWithAlert } from "@stackframe/stack-shared/dist/utils/promises";
15
- import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, ActionCell, Badge, Button, Input, Label, PasswordInput, Separator, Skeleton, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Typography } from "@stackframe/stack-ui";
16
- import { Edit, Trash, icons } from "lucide-react";
17
- import * as QRCode from "qrcode";
18
- import { Suspense, useEffect, useState } from "react";
19
- import { useForm } from "react-hook-form";
20
- import * as yup from "yup";
21
- import { MessageCard, useStackApp, useUser } from "..";
22
- import { CreateApiKeyDialog, ShowApiKeyDialog } from "../components/api-key-dialogs";
23
- import { ApiKeyTable } from "../components/api-key-table";
24
- import { FormWarningText } from "../components/elements/form-warning";
5
+ import { Skeleton, Typography } from "@stackframe/stack-ui";
6
+ import { icons } from "lucide-react";
7
+ import { Suspense } from "react";
8
+ import { useStackApp, useUser } from "..";
25
9
  import { MaybeFullPage } from "../components/elements/maybe-full-page";
26
10
  import { SidebarLayout } from "../components/elements/sidebar-layout";
27
- import { UserAvatar } from "../components/elements/user-avatar";
28
- import { ProfileImageEditor } from "../components/profile-image-editor";
29
11
  import { TeamIcon } from "../components/team-icon";
30
12
  import { useTranslation } from "../lib/translations";
31
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
+ import { ActiveSessionsPage } from "./account-settings/active-sessions/active-sessions-page";
14
+ import { ApiKeysPage } from "./account-settings/api-keys/api-keys-page";
15
+ import { EmailsAndAuthPage } from "./account-settings/email-and-auth/email-and-auth-page";
16
+ import { ProfilePage } from "./account-settings/profile-page/profile-page";
17
+ import { SettingsPage } from "./account-settings/settings/settings-page";
18
+ import { TeamCreationPage } from "./account-settings/teams/team-creation-page";
19
+ import { TeamPage } from "./account-settings/teams/team-page";
20
+ import { jsx, jsxs } from "react/jsx-runtime";
32
21
  var Icon = ({ name }) => {
33
22
  const LucideIcon = icons[name];
34
23
  return /* @__PURE__ */ jsx(LucideIcon, { className: "mr-2 h-4 w-4" });
@@ -111,416 +100,16 @@ function AccountSettings(props) {
111
100
  icon: /* @__PURE__ */ jsx(Icon, { name: "CirclePlus" }),
112
101
  type: "item",
113
102
  id: "team-creation",
114
- content: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(TeamCreationSkeleton, {}), children: /* @__PURE__ */ jsx(TeamCreation, {}) })
103
+ content: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(TeamCreationSkeleton, {}), children: /* @__PURE__ */ jsx(TeamCreationPage, {}) })
115
104
  }] : []
116
105
  ].filter((p) => p.type === "divider" || p.content),
117
106
  title: t("Account Settings")
118
107
  }
119
108
  ) }) });
120
109
  }
121
- function Section(props) {
122
- return /* @__PURE__ */ jsxs(Fragment, { children: [
123
- /* @__PURE__ */ jsx(Separator, {}),
124
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col sm:flex-row gap-2", children: [
125
- /* @__PURE__ */ jsxs("div", { className: "sm:flex-1 flex flex-col justify-center", children: [
126
- /* @__PURE__ */ jsx(Typography, { className: "font-medium", children: props.title }),
127
- props.description && /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "footnote", children: props.description })
128
- ] }),
129
- /* @__PURE__ */ jsx("div", { className: "sm:flex-1 sm:items-end flex flex-col gap-2 ", children: props.children })
130
- ] })
131
- ] });
132
- }
133
110
  function PageLayout(props) {
134
111
  return /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-6", children: props.children });
135
112
  }
136
- function ApiKeysPage() {
137
- const { t } = useTranslation();
138
- const user = useUser({ or: "redirect" });
139
- const apiKeys = user.useApiKeys();
140
- const [isNewApiKeyDialogOpen, setIsNewApiKeyDialogOpen] = useState(false);
141
- const [returnedApiKey, setReturnedApiKey] = useState(null);
142
- const CreateDialog = CreateApiKeyDialog;
143
- const ShowDialog = ShowApiKeyDialog;
144
- return /* @__PURE__ */ jsxs(PageLayout, { children: [
145
- /* @__PURE__ */ jsx(Button, { onClick: () => setIsNewApiKeyDialogOpen(true), children: t("Create API Key") }),
146
- /* @__PURE__ */ jsx(ApiKeyTable, { apiKeys }),
147
- /* @__PURE__ */ jsx(
148
- CreateDialog,
149
- {
150
- open: isNewApiKeyDialogOpen,
151
- onOpenChange: setIsNewApiKeyDialogOpen,
152
- onKeyCreated: setReturnedApiKey,
153
- createApiKey: async (data) => {
154
- const apiKey = await user.createApiKey(data);
155
- return apiKey;
156
- }
157
- }
158
- ),
159
- /* @__PURE__ */ jsx(
160
- ShowDialog,
161
- {
162
- apiKey: returnedApiKey,
163
- onClose: () => setReturnedApiKey(null)
164
- }
165
- )
166
- ] });
167
- }
168
- function TeamApiKeysSection(props) {
169
- const user = useUser({ or: "redirect" });
170
- const team = user.useTeam(props.team.id);
171
- if (!team) {
172
- throw new StackAssertionError("Team not found");
173
- }
174
- const manageApiKeysPermission = user.usePermission(props.team, "$manage_api_keys");
175
- if (!manageApiKeysPermission) {
176
- return null;
177
- }
178
- return /* @__PURE__ */ jsx(TeamApiKeysSectionInner, { team: props.team });
179
- }
180
- function TeamApiKeysSectionInner(props) {
181
- const { t } = useTranslation();
182
- const [isNewApiKeyDialogOpen, setIsNewApiKeyDialogOpen] = useState(false);
183
- const [returnedApiKey, setReturnedApiKey] = useState(null);
184
- const apiKeys = props.team.useApiKeys();
185
- const CreateDialog = CreateApiKeyDialog;
186
- const ShowDialog = ShowApiKeyDialog;
187
- return /* @__PURE__ */ jsxs(Fragment, { children: [
188
- /* @__PURE__ */ jsx(
189
- Section,
190
- {
191
- title: t("API Keys"),
192
- description: t("API keys grant programmatic access to your team."),
193
- children: /* @__PURE__ */ jsx(Button, { onClick: () => setIsNewApiKeyDialogOpen(true), children: t("Create API Key") })
194
- }
195
- ),
196
- /* @__PURE__ */ jsx(ApiKeyTable, { apiKeys }),
197
- /* @__PURE__ */ jsx(
198
- CreateDialog,
199
- {
200
- open: isNewApiKeyDialogOpen,
201
- onOpenChange: setIsNewApiKeyDialogOpen,
202
- onKeyCreated: setReturnedApiKey,
203
- createApiKey: async (data) => {
204
- const apiKey = await props.team.createApiKey(data);
205
- return apiKey;
206
- }
207
- }
208
- ),
209
- /* @__PURE__ */ jsx(
210
- ShowDialog,
211
- {
212
- apiKey: returnedApiKey,
213
- onClose: () => setReturnedApiKey(null)
214
- }
215
- )
216
- ] });
217
- }
218
- function ProfilePage() {
219
- const { t } = useTranslation();
220
- const user = useUser({ or: "redirect" });
221
- return /* @__PURE__ */ jsxs(PageLayout, { children: [
222
- /* @__PURE__ */ jsx(
223
- Section,
224
- {
225
- title: t("User name"),
226
- description: t("This is a display name and is not used for authentication"),
227
- children: /* @__PURE__ */ jsx(
228
- EditableText,
229
- {
230
- value: user.displayName || "",
231
- onSave: async (newDisplayName) => {
232
- await user.update({ displayName: newDisplayName });
233
- }
234
- }
235
- )
236
- }
237
- ),
238
- /* @__PURE__ */ jsx(
239
- Section,
240
- {
241
- title: t("Profile image"),
242
- description: t("Upload your own image as your avatar"),
243
- children: /* @__PURE__ */ jsx(
244
- ProfileImageEditor,
245
- {
246
- user,
247
- onProfileImageUrlChange: async (profileImageUrl) => {
248
- await user.update({ profileImageUrl });
249
- }
250
- }
251
- )
252
- }
253
- )
254
- ] });
255
- }
256
- function EmailsSection() {
257
- const { t } = useTranslation();
258
- const user = useUser({ or: "redirect" });
259
- const contactChannels = user.useContactChannels();
260
- const [addingEmail, setAddingEmail] = useState(contactChannels.length === 0);
261
- const [addingEmailLoading, setAddingEmailLoading] = useState(false);
262
- const [addedEmail, setAddedEmail] = useState(null);
263
- const isLastEmail = contactChannels.filter((x) => x.usedForAuth && x.type === "email").length === 1;
264
- useEffect(() => {
265
- if (addedEmail) {
266
- runAsynchronously(async () => {
267
- const cc = contactChannels.find((x) => x.value === addedEmail);
268
- if (cc && !cc.isVerified) {
269
- await cc.sendVerificationEmail();
270
- }
271
- setAddedEmail(null);
272
- });
273
- }
274
- }, [contactChannels, addedEmail]);
275
- const emailSchema = yupObject({
276
- email: strictEmailSchema(t("Please enter a valid email address")).notOneOf(contactChannels.map((x) => x.value), t("Email already exists")).defined().nonEmpty(t("Email is required"))
277
- });
278
- const { register, handleSubmit, formState: { errors }, reset } = useForm({
279
- resolver: yupResolver(emailSchema)
280
- });
281
- const onSubmit = async (data) => {
282
- setAddingEmailLoading(true);
283
- try {
284
- await user.createContactChannel({ type: "email", value: data.email, usedForAuth: false });
285
- setAddedEmail(data.email);
286
- } finally {
287
- setAddingEmailLoading(false);
288
- }
289
- setAddingEmail(false);
290
- reset();
291
- };
292
- return /* @__PURE__ */ jsxs("div", { children: [
293
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col md:flex-row justify-between mb-4 gap-4", children: [
294
- /* @__PURE__ */ jsx(Typography, { className: "font-medium", children: t("Emails") }),
295
- addingEmail ? /* @__PURE__ */ jsxs(
296
- "form",
297
- {
298
- onSubmit: (e) => {
299
- e.preventDefault();
300
- runAsynchronously(handleSubmit(onSubmit));
301
- },
302
- className: "flex flex-col",
303
- children: [
304
- /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
305
- /* @__PURE__ */ jsx(
306
- Input,
307
- {
308
- ...register("email"),
309
- placeholder: t("Enter email")
310
- }
311
- ),
312
- /* @__PURE__ */ jsx(Button, { type: "submit", loading: addingEmailLoading, children: t("Add") }),
313
- /* @__PURE__ */ jsx(
314
- Button,
315
- {
316
- variant: "secondary",
317
- onClick: () => {
318
- setAddingEmail(false);
319
- reset();
320
- },
321
- children: t("Cancel")
322
- }
323
- )
324
- ] }),
325
- errors.email && /* @__PURE__ */ jsx(FormWarningText, { text: errors.email.message })
326
- ]
327
- }
328
- ) : /* @__PURE__ */ jsx("div", { className: "flex md:justify-end", children: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => setAddingEmail(true), children: t("Add an email") }) })
329
- ] }),
330
- contactChannels.length > 0 ? /* @__PURE__ */ jsx("div", { className: "border rounded-md", children: /* @__PURE__ */ jsx(Table, { children: /* @__PURE__ */ jsx(TableBody, { children: contactChannels.filter((x) => x.type === "email").sort((a, b) => {
331
- if (a.isPrimary !== b.isPrimary) return a.isPrimary ? -1 : 1;
332
- if (a.isVerified !== b.isVerified) return a.isVerified ? -1 : 1;
333
- return 0;
334
- }).map((x) => /* @__PURE__ */ jsxs(TableRow, { children: [
335
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col md:flex-row gap-2 md:gap-4", children: [
336
- x.value,
337
- /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
338
- x.isPrimary ? /* @__PURE__ */ jsx(Badge, { children: t("Primary") }) : null,
339
- !x.isVerified ? /* @__PURE__ */ jsx(Badge, { variant: "destructive", children: t("Unverified") }) : null,
340
- x.usedForAuth ? /* @__PURE__ */ jsx(Badge, { variant: "outline", children: t("Used for sign-in") }) : null
341
- ] })
342
- ] }) }),
343
- /* @__PURE__ */ jsx(TableCell, { className: "flex justify-end", children: /* @__PURE__ */ jsx(ActionCell, { items: [
344
- ...!x.isVerified ? [{
345
- item: t("Send verification email"),
346
- onClick: async () => {
347
- await x.sendVerificationEmail();
348
- }
349
- }] : [],
350
- ...!x.isPrimary && x.isVerified ? [{
351
- item: t("Set as primary"),
352
- onClick: async () => {
353
- await x.update({ isPrimary: true });
354
- }
355
- }] : !x.isPrimary ? [{
356
- item: t("Set as primary"),
357
- onClick: async () => {
358
- },
359
- disabled: true,
360
- disabledTooltip: t("Please verify your email first")
361
- }] : [],
362
- ...!x.usedForAuth && x.isVerified ? [{
363
- item: t("Use for sign-in"),
364
- onClick: async () => {
365
- try {
366
- await x.update({ usedForAuth: true });
367
- } catch (e) {
368
- if (e instanceof KnownErrors.ContactChannelAlreadyUsedForAuthBySomeoneElse) {
369
- alert(t("This email is already used for sign-in by another user."));
370
- }
371
- }
372
- }
373
- }] : [],
374
- ...x.usedForAuth && !isLastEmail ? [{
375
- item: t("Stop using for sign-in"),
376
- onClick: async () => {
377
- await x.update({ usedForAuth: false });
378
- }
379
- }] : x.usedForAuth ? [{
380
- item: t("Stop using for sign-in"),
381
- onClick: async () => {
382
- },
383
- disabled: true,
384
- disabledTooltip: t("You can not remove your last sign-in email")
385
- }] : [],
386
- ...!isLastEmail || !x.usedForAuth ? [{
387
- item: t("Remove"),
388
- onClick: async () => {
389
- await x.delete();
390
- },
391
- danger: true
392
- }] : [{
393
- item: t("Remove"),
394
- onClick: async () => {
395
- },
396
- disabled: true,
397
- disabledTooltip: t("You can not remove your last sign-in email")
398
- }]
399
- ] }) })
400
- ] }, x.id)) }) }) }) : null
401
- ] });
402
- }
403
- function EmailsAndAuthPage() {
404
- return /* @__PURE__ */ jsxs(PageLayout, { children: [
405
- /* @__PURE__ */ jsx(EmailsSection, {}),
406
- /* @__PURE__ */ jsx(PasswordSection, {}),
407
- /* @__PURE__ */ jsx(PasskeySection, {}),
408
- /* @__PURE__ */ jsx(OtpSection, {}),
409
- /* @__PURE__ */ jsx(MfaSection, {})
410
- ] });
411
- }
412
- function ActiveSessionsPage() {
413
- const { t } = useTranslation();
414
- const user = useUser({ or: "throw" });
415
- const [isLoading, setIsLoading] = useState(true);
416
- const [isRevokingAll, setIsRevokingAll] = useState(false);
417
- const [sessions, setSessions] = useState([]);
418
- const [showConfirmRevokeAll, setShowConfirmRevokeAll] = useState(false);
419
- useEffect(() => {
420
- runAsynchronously(async () => {
421
- setIsLoading(true);
422
- const sessionsData = await user.getActiveSessions();
423
- const enhancedSessions = sessionsData;
424
- setSessions(enhancedSessions);
425
- setIsLoading(false);
426
- });
427
- }, [user]);
428
- const handleRevokeSession = async (sessionId) => {
429
- try {
430
- await user.revokeSession(sessionId);
431
- setSessions(sessions.filter((session) => session.id !== sessionId));
432
- } catch (error) {
433
- captureError("Failed to revoke session", { sessionId, error });
434
- throw error;
435
- }
436
- };
437
- const handleRevokeAllSessions = async () => {
438
- setIsRevokingAll(true);
439
- try {
440
- const deletionPromises = sessions.filter((session) => !session.isCurrentSession).map((session) => user.revokeSession(session.id));
441
- await Promise.all(deletionPromises);
442
- setSessions((prevSessions) => prevSessions.filter((session) => session.isCurrentSession));
443
- } catch (error) {
444
- captureError("Failed to revoke all sessions", { error, sessionIds: sessions.map((session) => session.id) });
445
- throw error;
446
- } finally {
447
- setIsRevokingAll(false);
448
- setShowConfirmRevokeAll(false);
449
- }
450
- };
451
- return /* @__PURE__ */ jsx(PageLayout, { children: /* @__PURE__ */ jsxs("div", { children: [
452
- /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center mb-2", children: [
453
- /* @__PURE__ */ jsx(Typography, { className: "font-medium", children: t("Active Sessions") }),
454
- sessions.filter((s) => !s.isCurrentSession).length > 0 && !isLoading && (showConfirmRevokeAll ? /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
455
- /* @__PURE__ */ jsx(
456
- Button,
457
- {
458
- variant: "destructive",
459
- size: "sm",
460
- loading: isRevokingAll,
461
- onClick: handleRevokeAllSessions,
462
- children: t("Confirm")
463
- }
464
- ),
465
- /* @__PURE__ */ jsx(
466
- Button,
467
- {
468
- variant: "secondary",
469
- size: "sm",
470
- disabled: isRevokingAll,
471
- onClick: () => setShowConfirmRevokeAll(false),
472
- children: t("Cancel")
473
- }
474
- )
475
- ] }) : /* @__PURE__ */ jsx(
476
- Button,
477
- {
478
- variant: "outline",
479
- size: "sm",
480
- onClick: () => setShowConfirmRevokeAll(true),
481
- children: t("Revoke All Other Sessions")
482
- }
483
- ))
484
- ] }),
485
- /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "footnote", className: "mb-4", children: t("These are devices where you're currently logged in. You can revoke access to end a session.") }),
486
- isLoading ? /* @__PURE__ */ jsx(Skeleton, { className: "h-[300px] w-full rounded-md" }) : /* @__PURE__ */ jsx("div", { className: "border rounded-md", children: /* @__PURE__ */ jsxs(Table, { children: [
487
- /* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { children: [
488
- /* @__PURE__ */ jsx(TableHead, { className: "w-[200px]", children: t("Session") }),
489
- /* @__PURE__ */ jsx(TableHead, { className: "w-[150px]", children: t("IP Address") }),
490
- /* @__PURE__ */ jsx(TableHead, { className: "w-[150px]", children: t("Location") }),
491
- /* @__PURE__ */ jsx(TableHead, { className: "w-[150px]", children: t("Last used") }),
492
- /* @__PURE__ */ jsx(TableHead, { className: "w-[80px]" })
493
- ] }) }),
494
- /* @__PURE__ */ jsx(TableBody, { children: sessions.length === 0 ? /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, { colSpan: 5, className: "text-center py-6", children: /* @__PURE__ */ jsx(Typography, { variant: "secondary", children: t("No active sessions found") }) }) }) : sessions.map((session) => /* @__PURE__ */ jsxs(TableRow, { children: [
495
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
496
- /* @__PURE__ */ jsx(Typography, { children: session.isCurrentSession ? t("Current Session") : t("Other Session") }),
497
- session.isImpersonation && /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "w-fit mt-1", children: t("Impersonation") }),
498
- /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "footnote", children: t("Signed in {time}", { time: new Date(session.createdAt).toLocaleDateString() }) })
499
- ] }) }),
500
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, { children: session.geoInfo?.ip || t("-") }) }),
501
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, { children: session.geoInfo?.cityName || t("Unknown") }) }),
502
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
503
- /* @__PURE__ */ jsx(Typography, { children: session.lastUsedAt ? fromNow(new Date(session.lastUsedAt)) : t("Never") }),
504
- /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "footnote", title: session.lastUsedAt ? new Date(session.lastUsedAt).toLocaleString() : "", children: session.lastUsedAt ? new Date(session.lastUsedAt).toLocaleDateString() : "" })
505
- ] }) }),
506
- /* @__PURE__ */ jsx(TableCell, { align: "right", children: /* @__PURE__ */ jsx(
507
- ActionCell,
508
- {
509
- items: [
510
- {
511
- item: t("Revoke"),
512
- onClick: () => handleRevokeSession(session.id),
513
- danger: true,
514
- disabled: session.isCurrentSession,
515
- disabledTooltip: session.isCurrentSession ? t("You cannot revoke your current session") : void 0
516
- }
517
- ]
518
- }
519
- ) })
520
- ] }, session.id)) })
521
- ] }) })
522
- ] }) });
523
- }
524
113
  function EmailsAndAuthPageSkeleton() {
525
114
  return /* @__PURE__ */ jsxs(PageLayout, { children: [
526
115
  /* @__PURE__ */ jsx(Skeleton, { className: "h-9 w-full mt-1" }),
@@ -536,736 +125,6 @@ function ActiveSessionsPageSkeleton() {
536
125
  /* @__PURE__ */ jsx(Skeleton, { className: "h-[200px] w-full mt-1 rounded-md" })
537
126
  ] });
538
127
  }
539
- function PasskeySection() {
540
- const { t } = useTranslation();
541
- const user = useUser({ or: "throw" });
542
- const stackApp = useStackApp();
543
- const project = stackApp.useProject();
544
- const contactChannels = user.useContactChannels();
545
- const hasPasskey = user.passkeyAuthEnabled;
546
- const isLastAuth = user.passkeyAuthEnabled && !user.hasPassword && user.oauthProviders.length === 0 && !user.otpAuthEnabled;
547
- const [showConfirmationModal, setShowConfirmationModal] = useState(false);
548
- const hasValidEmail = contactChannels.filter((x) => x.type === "email" && x.isVerified && x.usedForAuth).length > 0;
549
- if (!project.config.passkeyEnabled) {
550
- return null;
551
- }
552
- const handleDeletePasskey = async () => {
553
- await user.update({ passkeyAuthEnabled: false });
554
- setShowConfirmationModal(false);
555
- };
556
- const handleAddNewPasskey = async () => {
557
- await user.registerPasskey();
558
- };
559
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Section, { title: t("Passkey"), description: hasPasskey ? t("Passkey registered") : t("Register a passkey"), children: /* @__PURE__ */ jsxs("div", { className: "flex md:justify-end gap-2", children: [
560
- !hasValidEmail && /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "label", children: t("To enable Passkey sign-in, please add a verified sign-in email.") }),
561
- hasValidEmail && hasPasskey && isLastAuth && /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "label", children: t("Passkey sign-in is enabled and cannot be disabled as it is currently the only sign-in method") }),
562
- !hasPasskey && hasValidEmail && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, { onClick: handleAddNewPasskey, variant: "secondary", children: t("Add new passkey") }) }),
563
- hasValidEmail && hasPasskey && !isLastAuth && !showConfirmationModal && /* @__PURE__ */ jsx(
564
- Button,
565
- {
566
- variant: "secondary",
567
- onClick: () => setShowConfirmationModal(true),
568
- children: t("Delete Passkey")
569
- }
570
- ),
571
- hasValidEmail && hasPasskey && !isLastAuth && showConfirmationModal && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
572
- /* @__PURE__ */ jsx(Typography, { variant: "destructive", children: t("Are you sure you want to disable Passkey sign-in? You will not be able to sign in with your passkey anymore.") }),
573
- /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
574
- /* @__PURE__ */ jsx(
575
- Button,
576
- {
577
- variant: "destructive",
578
- onClick: handleDeletePasskey,
579
- children: t("Disable")
580
- }
581
- ),
582
- /* @__PURE__ */ jsx(
583
- Button,
584
- {
585
- variant: "secondary",
586
- onClick: () => setShowConfirmationModal(false),
587
- children: t("Cancel")
588
- }
589
- )
590
- ] })
591
- ] })
592
- ] }) }) });
593
- }
594
- function OtpSection() {
595
- const { t } = useTranslation();
596
- const user = useUser({ or: "throw" });
597
- const project = useStackApp().useProject();
598
- const contactChannels = user.useContactChannels();
599
- const isLastAuth = user.otpAuthEnabled && !user.hasPassword && user.oauthProviders.length === 0 && !user.passkeyAuthEnabled;
600
- const [disabling, setDisabling] = useState(false);
601
- const hasValidEmail = contactChannels.filter((x) => x.type === "email" && x.isVerified && x.usedForAuth).length > 0;
602
- if (!project.config.magicLinkEnabled) {
603
- return null;
604
- }
605
- const handleDisableOTP = async () => {
606
- await user.update({ otpAuthEnabled: false });
607
- setDisabling(false);
608
- };
609
- return /* @__PURE__ */ jsx(Section, { title: t("OTP sign-in"), description: user.otpAuthEnabled ? t("OTP/magic link sign-in is currently enabled.") : t("Enable sign-in via magic link or OTP sent to your sign-in emails."), children: /* @__PURE__ */ jsx("div", { className: "flex md:justify-end", children: hasValidEmail ? user.otpAuthEnabled ? !isLastAuth ? !disabling ? /* @__PURE__ */ jsx(
610
- Button,
611
- {
612
- variant: "secondary",
613
- onClick: () => setDisabling(true),
614
- children: t("Disable OTP")
615
- }
616
- ) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
617
- /* @__PURE__ */ jsx(Typography, { variant: "destructive", children: t("Are you sure you want to disable OTP sign-in? You will not be able to sign in with only emails anymore.") }),
618
- /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
619
- /* @__PURE__ */ jsx(
620
- Button,
621
- {
622
- variant: "destructive",
623
- onClick: handleDisableOTP,
624
- children: t("Disable")
625
- }
626
- ),
627
- /* @__PURE__ */ jsx(
628
- Button,
629
- {
630
- variant: "secondary",
631
- onClick: () => setDisabling(false),
632
- children: t("Cancel")
633
- }
634
- )
635
- ] })
636
- ] }) : /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "label", children: t("OTP sign-in is enabled and cannot be disabled as it is currently the only sign-in method") }) : /* @__PURE__ */ jsx(
637
- Button,
638
- {
639
- variant: "secondary",
640
- onClick: async () => {
641
- await user.update({ otpAuthEnabled: true });
642
- },
643
- children: t("Enable OTP")
644
- }
645
- ) : /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "label", children: t("To enable OTP sign-in, please add a verified sign-in email.") }) }) });
646
- }
647
- function SettingsPage() {
648
- return /* @__PURE__ */ jsxs(PageLayout, { children: [
649
- /* @__PURE__ */ jsx(DeleteAccountSection, {}),
650
- /* @__PURE__ */ jsx(SignOutSection, {})
651
- ] });
652
- }
653
- function PasswordSection() {
654
- const { t } = useTranslation();
655
- const user = useUser({ or: "throw" });
656
- const contactChannels = user.useContactChannels();
657
- const [changingPassword, setChangingPassword] = useState(false);
658
- const [loading, setLoading] = useState(false);
659
- const project = useStackApp().useProject();
660
- const passwordSchema = yupObject({
661
- oldPassword: user.hasPassword ? schemaFieldsPasswordSchema.defined().nonEmpty(t("Please enter your old password")) : yupString(),
662
- newPassword: schemaFieldsPasswordSchema.defined().nonEmpty(t("Please enter your password")).test({
663
- name: "is-valid-password",
664
- test: (value, ctx) => {
665
- const error = getPasswordError(value);
666
- if (error) {
667
- return ctx.createError({ message: error.message });
668
- } else {
669
- return true;
670
- }
671
- }
672
- }),
673
- newPasswordRepeat: yupString().nullable().oneOf([yup.ref("newPassword"), "", null], t("Passwords do not match")).defined().nonEmpty(t("Please repeat your password"))
674
- });
675
- const { register, handleSubmit, setError, formState: { errors }, clearErrors, reset } = useForm({
676
- resolver: yupResolver(passwordSchema)
677
- });
678
- const hasValidEmail = contactChannels.filter((x) => x.type === "email" && x.usedForAuth).length > 0;
679
- const onSubmit = async (data) => {
680
- setLoading(true);
681
- try {
682
- const { oldPassword, newPassword } = data;
683
- const error = user.hasPassword ? await user.updatePassword({ oldPassword, newPassword }) : await user.setPassword({ password: newPassword });
684
- if (error) {
685
- setError("oldPassword", { type: "manual", message: t("Incorrect password") });
686
- } else {
687
- reset();
688
- setChangingPassword(false);
689
- }
690
- } finally {
691
- setLoading(false);
692
- }
693
- };
694
- const registerPassword = register("newPassword");
695
- const registerPasswordRepeat = register("newPasswordRepeat");
696
- if (!project.config.credentialEnabled) {
697
- return null;
698
- }
699
- return /* @__PURE__ */ jsx(
700
- Section,
701
- {
702
- title: t("Password"),
703
- description: user.hasPassword ? t("Update your password") : t("Set a password for your account"),
704
- children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-4", children: !changingPassword ? hasValidEmail ? /* @__PURE__ */ jsx(
705
- Button,
706
- {
707
- variant: "secondary",
708
- onClick: () => setChangingPassword(true),
709
- children: user.hasPassword ? t("Update password") : t("Set password")
710
- }
711
- ) : /* @__PURE__ */ jsx(Typography, { variant: "secondary", type: "label", children: t("To set a password, please add a sign-in email.") }) : /* @__PURE__ */ jsxs(
712
- "form",
713
- {
714
- onSubmit: (e) => runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e)),
715
- noValidate: true,
716
- children: [
717
- user.hasPassword && /* @__PURE__ */ jsxs(Fragment, { children: [
718
- /* @__PURE__ */ jsx(Label, { htmlFor: "old-password", className: "mb-1", children: t("Old password") }),
719
- /* @__PURE__ */ jsx(
720
- Input,
721
- {
722
- id: "old-password",
723
- type: "password",
724
- autoComplete: "current-password",
725
- ...register("oldPassword")
726
- }
727
- ),
728
- /* @__PURE__ */ jsx(FormWarningText, { text: errors.oldPassword?.message?.toString() })
729
- ] }),
730
- /* @__PURE__ */ jsx(Label, { htmlFor: "new-password", className: "mt-4 mb-1", children: t("New password") }),
731
- /* @__PURE__ */ jsx(
732
- PasswordInput,
733
- {
734
- id: "new-password",
735
- autoComplete: "new-password",
736
- ...registerPassword,
737
- onChange: (e) => {
738
- clearErrors("newPassword");
739
- clearErrors("newPasswordRepeat");
740
- runAsynchronously(registerPassword.onChange(e));
741
- }
742
- }
743
- ),
744
- /* @__PURE__ */ jsx(FormWarningText, { text: errors.newPassword?.message?.toString() }),
745
- /* @__PURE__ */ jsx(Label, { htmlFor: "repeat-password", className: "mt-4 mb-1", children: t("Repeat new password") }),
746
- /* @__PURE__ */ jsx(
747
- PasswordInput,
748
- {
749
- id: "repeat-password",
750
- autoComplete: "new-password",
751
- ...registerPasswordRepeat,
752
- onChange: (e) => {
753
- clearErrors("newPassword");
754
- clearErrors("newPasswordRepeat");
755
- runAsynchronously(registerPasswordRepeat.onChange(e));
756
- }
757
- }
758
- ),
759
- /* @__PURE__ */ jsx(FormWarningText, { text: errors.newPasswordRepeat?.message?.toString() }),
760
- /* @__PURE__ */ jsxs("div", { className: "mt-6 flex gap-4", children: [
761
- /* @__PURE__ */ jsx(Button, { type: "submit", loading, children: user.hasPassword ? t("Update Password") : t("Set Password") }),
762
- /* @__PURE__ */ jsx(
763
- Button,
764
- {
765
- variant: "secondary",
766
- onClick: () => {
767
- setChangingPassword(false);
768
- reset();
769
- },
770
- children: t("Cancel")
771
- }
772
- )
773
- ] })
774
- ]
775
- }
776
- ) })
777
- }
778
- );
779
- }
780
- function MfaSection() {
781
- const { t } = useTranslation();
782
- const project = useStackApp().useProject();
783
- const user = useUser({ or: "throw" });
784
- const [generatedSecret, setGeneratedSecret] = useState(null);
785
- const [qrCodeUrl, setQrCodeUrl] = useState(null);
786
- const [mfaCode, setMfaCode] = useState("");
787
- const [isMaybeWrong, setIsMaybeWrong] = useState(false);
788
- const isEnabled = user.isMultiFactorRequired;
789
- const [handleSubmit, isLoading] = useAsyncCallback(async () => {
790
- await user.update({
791
- totpMultiFactorSecret: generatedSecret
792
- });
793
- setGeneratedSecret(null);
794
- setQrCodeUrl(null);
795
- setMfaCode("");
796
- }, [generatedSecret, user]);
797
- useEffect(() => {
798
- setIsMaybeWrong(false);
799
- runAsynchronouslyWithAlert(async () => {
800
- if (generatedSecret && verifyTOTP(generatedSecret, 30, 6, mfaCode)) {
801
- await handleSubmit();
802
- }
803
- setIsMaybeWrong(true);
804
- });
805
- }, [mfaCode, generatedSecret, handleSubmit]);
806
- return /* @__PURE__ */ jsx(
807
- Section,
808
- {
809
- title: t("Multi-factor authentication"),
810
- description: isEnabled ? t("Multi-factor authentication is currently enabled.") : t("Multi-factor authentication is currently disabled."),
811
- children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
812
- !isEnabled && generatedSecret && /* @__PURE__ */ jsxs(Fragment, { children: [
813
- /* @__PURE__ */ jsx(Typography, { children: t("Scan this QR code with your authenticator app:") }),
814
- /* @__PURE__ */ jsx("img", { width: 200, height: 200, src: qrCodeUrl ?? throwErr("TOTP QR code failed to generate"), alt: t("TOTP multi-factor authentication QR code") }),
815
- /* @__PURE__ */ jsx(Typography, { children: t("Then, enter your six-digit MFA code:") }),
816
- /* @__PURE__ */ jsx(
817
- Input,
818
- {
819
- value: mfaCode,
820
- onChange: (e) => {
821
- setIsMaybeWrong(false);
822
- setMfaCode(e.target.value);
823
- },
824
- placeholder: "123456",
825
- maxLength: 6,
826
- disabled: isLoading
827
- }
828
- ),
829
- isMaybeWrong && mfaCode.length === 6 && /* @__PURE__ */ jsx(Typography, { variant: "destructive", children: t("Incorrect code. Please try again.") }),
830
- /* @__PURE__ */ jsx("div", { className: "flex", children: /* @__PURE__ */ jsx(
831
- Button,
832
- {
833
- variant: "secondary",
834
- onClick: () => {
835
- setGeneratedSecret(null);
836
- setQrCodeUrl(null);
837
- setMfaCode("");
838
- },
839
- children: t("Cancel")
840
- }
841
- ) })
842
- ] }),
843
- /* @__PURE__ */ jsx("div", { className: "flex gap-2", children: isEnabled ? /* @__PURE__ */ jsx(
844
- Button,
845
- {
846
- variant: "secondary",
847
- onClick: async () => {
848
- await user.update({
849
- totpMultiFactorSecret: null
850
- });
851
- },
852
- children: t("Disable MFA")
853
- }
854
- ) : !generatedSecret && /* @__PURE__ */ jsx(
855
- Button,
856
- {
857
- variant: "secondary",
858
- onClick: async () => {
859
- const secret = generateRandomValues(new Uint8Array(20));
860
- setQrCodeUrl(await generateTotpQrCode(project, user, secret));
861
- setGeneratedSecret(secret);
862
- },
863
- children: t("Enable MFA")
864
- }
865
- ) })
866
- ] })
867
- }
868
- );
869
- }
870
- async function generateTotpQrCode(project, user, secret) {
871
- const uri = createTOTPKeyURI(project.displayName, user.primaryEmail ?? user.id, secret, 30, 6);
872
- return await QRCode.toDataURL(uri);
873
- }
874
- function SignOutSection() {
875
- const { t } = useTranslation();
876
- const user = useUser({ or: "throw" });
877
- return /* @__PURE__ */ jsx(
878
- Section,
879
- {
880
- title: t("Sign out"),
881
- description: t("End your current session"),
882
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
883
- Button,
884
- {
885
- variant: "secondary",
886
- onClick: () => user.signOut(),
887
- children: t("Sign out")
888
- }
889
- ) })
890
- }
891
- );
892
- }
893
- function TeamPage(props) {
894
- return /* @__PURE__ */ jsxs(PageLayout, { children: [
895
- /* @__PURE__ */ jsx(TeamUserProfileSection, { team: props.team }, `user-profile-${props.team.id}`),
896
- /* @__PURE__ */ jsx(TeamProfileImageSection, { team: props.team }, `profile-image-${props.team.id}`),
897
- /* @__PURE__ */ jsx(TeamDisplayNameSection, { team: props.team }, `display-name-${props.team.id}`),
898
- /* @__PURE__ */ jsx(MemberListSection, { team: props.team }, `member-list-${props.team.id}`),
899
- /* @__PURE__ */ jsx(MemberInvitationSection, { team: props.team }, `member-invitation-${props.team.id}`),
900
- /* @__PURE__ */ jsx(TeamApiKeysSection, { team: props.team }, `api-keys-${props.team.id}`),
901
- /* @__PURE__ */ jsx(LeaveTeamSection, { team: props.team }, `leave-team-${props.team.id}`)
902
- ] });
903
- }
904
- function LeaveTeamSection(props) {
905
- const { t } = useTranslation();
906
- const user = useUser({ or: "redirect" });
907
- const [leaving, setLeaving] = useState(false);
908
- return /* @__PURE__ */ jsx(
909
- Section,
910
- {
911
- title: t("Leave Team"),
912
- description: t("leave this team and remove your team profile"),
913
- children: !leaving ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
914
- Button,
915
- {
916
- variant: "secondary",
917
- onClick: () => setLeaving(true),
918
- children: t("Leave team")
919
- }
920
- ) }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
921
- /* @__PURE__ */ jsx(Typography, { variant: "destructive", children: t("Are you sure you want to leave the team?") }),
922
- /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
923
- /* @__PURE__ */ jsx(
924
- Button,
925
- {
926
- variant: "destructive",
927
- onClick: async () => {
928
- await user.leaveTeam(props.team);
929
- window.location.reload();
930
- },
931
- children: t("Leave")
932
- }
933
- ),
934
- /* @__PURE__ */ jsx(
935
- Button,
936
- {
937
- variant: "secondary",
938
- onClick: () => setLeaving(false),
939
- children: t("Cancel")
940
- }
941
- )
942
- ] })
943
- ] })
944
- }
945
- );
946
- }
947
- function TeamProfileImageSection(props) {
948
- const { t } = useTranslation();
949
- const user = useUser({ or: "redirect" });
950
- const updateTeamPermission = user.usePermission(props.team, "$update_team");
951
- if (!updateTeamPermission) {
952
- return null;
953
- }
954
- return /* @__PURE__ */ jsx(
955
- Section,
956
- {
957
- title: t("Team profile image"),
958
- description: t("Upload an image for your team"),
959
- children: /* @__PURE__ */ jsx(
960
- ProfileImageEditor,
961
- {
962
- user: props.team,
963
- onProfileImageUrlChange: async (profileImageUrl) => {
964
- await props.team.update({ profileImageUrl });
965
- }
966
- }
967
- )
968
- }
969
- );
970
- }
971
- function TeamDisplayNameSection(props) {
972
- const { t } = useTranslation();
973
- const user = useUser({ or: "redirect" });
974
- const updateTeamPermission = user.usePermission(props.team, "$update_team");
975
- if (!updateTeamPermission) {
976
- return null;
977
- }
978
- return /* @__PURE__ */ jsx(
979
- Section,
980
- {
981
- title: t("Team display name"),
982
- description: t("Change the display name of your team"),
983
- children: /* @__PURE__ */ jsx(
984
- EditableText,
985
- {
986
- value: props.team.displayName,
987
- onSave: async (newDisplayName) => await props.team.update({ displayName: newDisplayName })
988
- }
989
- )
990
- }
991
- );
992
- }
993
- function TeamUserProfileSection(props) {
994
- const { t } = useTranslation();
995
- const user = useUser({ or: "redirect" });
996
- const profile = user.useTeamProfile(props.team);
997
- return /* @__PURE__ */ jsx(
998
- Section,
999
- {
1000
- title: t("Team user name"),
1001
- description: t("Overwrite your user display name in this team"),
1002
- children: /* @__PURE__ */ jsx(
1003
- EditableText,
1004
- {
1005
- value: profile.displayName || "",
1006
- onSave: async (newDisplayName) => {
1007
- await profile.update({ displayName: newDisplayName });
1008
- }
1009
- }
1010
- )
1011
- }
1012
- );
1013
- }
1014
- function MemberInvitationSection(props) {
1015
- const user = useUser({ or: "redirect" });
1016
- const inviteMemberPermission = user.usePermission(props.team, "$invite_members");
1017
- if (!inviteMemberPermission) {
1018
- return null;
1019
- }
1020
- return /* @__PURE__ */ jsx(MemberInvitationSectionInner, { team: props.team });
1021
- }
1022
- function MemberInvitationsSectionInvitationsList(props) {
1023
- const user = useUser({ or: "redirect" });
1024
- const { t } = useTranslation();
1025
- const invitationsToShow = props.team.useInvitations();
1026
- const removeMemberPermission = user.usePermission(props.team, "$remove_members");
1027
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Table, { className: "mt-6", children: [
1028
- /* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { children: [
1029
- /* @__PURE__ */ jsx(TableHead, { className: "w-[200px]", children: t("Outstanding invitations") }),
1030
- /* @__PURE__ */ jsx(TableHead, { className: "w-[60px]", children: t("Expires") }),
1031
- /* @__PURE__ */ jsx(TableHead, { className: "w-[36px] max-w-[36px]" })
1032
- ] }) }),
1033
- /* @__PURE__ */ jsxs(TableBody, { children: [
1034
- invitationsToShow.map((invitation, i) => /* @__PURE__ */ jsxs(TableRow, { children: [
1035
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, { children: invitation.recipientEmail }) }),
1036
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, { variant: "secondary", children: invitation.expiresAt.toLocaleString() }) }),
1037
- /* @__PURE__ */ jsx(TableCell, { align: "right", className: "max-w-[36px]", children: removeMemberPermission && /* @__PURE__ */ jsx(Button, { onClick: async () => await invitation.revoke(), size: "icon", variant: "ghost", children: /* @__PURE__ */ jsx(Trash, { className: "w-4 h-4" }) }) })
1038
- ] }, invitation.id)),
1039
- invitationsToShow.length === 0 && /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, { colSpan: 3, children: /* @__PURE__ */ jsx(Typography, { variant: "secondary", children: t("No outstanding invitations") }) }) })
1040
- ] })
1041
- ] }) });
1042
- }
1043
- function MemberInvitationSectionInner(props) {
1044
- const user = useUser({ or: "redirect" });
1045
- const { t } = useTranslation();
1046
- const readMemberPermission = user.usePermission(props.team, "$read_members");
1047
- const invitationSchema = yupObject({
1048
- email: strictEmailSchema(t("Please enter a valid email address")).defined().nonEmpty(t("Please enter an email address"))
1049
- });
1050
- const { register, handleSubmit, formState: { errors }, watch } = useForm({
1051
- resolver: yupResolver(invitationSchema)
1052
- });
1053
- const [loading, setLoading] = useState(false);
1054
- const [invitedEmail, setInvitedEmail] = useState(null);
1055
- const onSubmit = async (data) => {
1056
- setLoading(true);
1057
- try {
1058
- await props.team.inviteUser({ email: data.email });
1059
- setInvitedEmail(data.email);
1060
- } finally {
1061
- setLoading(false);
1062
- }
1063
- };
1064
- useEffect(() => {
1065
- setInvitedEmail(null);
1066
- }, [watch("email")]);
1067
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1068
- /* @__PURE__ */ jsx(
1069
- Section,
1070
- {
1071
- title: t("Invite member"),
1072
- description: t("Invite a user to your team through email"),
1073
- children: /* @__PURE__ */ jsxs(
1074
- "form",
1075
- {
1076
- onSubmit: (e) => runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e)),
1077
- noValidate: true,
1078
- className: "w-full",
1079
- children: [
1080
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 sm:flex-row w-full", children: [
1081
- /* @__PURE__ */ jsx(
1082
- Input,
1083
- {
1084
- placeholder: t("Email"),
1085
- ...register("email")
1086
- }
1087
- ),
1088
- /* @__PURE__ */ jsx(Button, { type: "submit", loading, children: t("Invite User") })
1089
- ] }),
1090
- /* @__PURE__ */ jsx(FormWarningText, { text: errors.email?.message?.toString() }),
1091
- invitedEmail && /* @__PURE__ */ jsxs(Typography, { type: "label", variant: "secondary", children: [
1092
- "Invited ",
1093
- invitedEmail
1094
- ] })
1095
- ]
1096
- }
1097
- )
1098
- }
1099
- ),
1100
- readMemberPermission && /* @__PURE__ */ jsx(MemberInvitationsSectionInvitationsList, { team: props.team })
1101
- ] });
1102
- }
1103
- function MemberListSection(props) {
1104
- const user = useUser({ or: "redirect" });
1105
- const readMemberPermission = user.usePermission(props.team, "$read_members");
1106
- const inviteMemberPermission = user.usePermission(props.team, "$invite_members");
1107
- if (!readMemberPermission && !inviteMemberPermission) {
1108
- return null;
1109
- }
1110
- return /* @__PURE__ */ jsx(MemberListSectionInner, { team: props.team });
1111
- }
1112
- function MemberListSectionInner(props) {
1113
- const { t } = useTranslation();
1114
- const users = props.team.useUsers();
1115
- return /* @__PURE__ */ jsxs("div", { children: [
1116
- /* @__PURE__ */ jsx(Typography, { className: "font-medium mb-2", children: t("Members") }),
1117
- /* @__PURE__ */ jsx("div", { className: "border rounded-md", children: /* @__PURE__ */ jsxs(Table, { children: [
1118
- /* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { children: [
1119
- /* @__PURE__ */ jsx(TableHead, { className: "w-[100px]", children: t("User") }),
1120
- /* @__PURE__ */ jsx(TableHead, { className: "w-[200px]", children: t("Name") })
1121
- ] }) }),
1122
- /* @__PURE__ */ jsx(TableBody, { children: users.map(({ id, teamProfile }, i) => /* @__PURE__ */ jsxs(TableRow, { children: [
1123
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(UserAvatar, { user: teamProfile }) }),
1124
- /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Typography, { children: teamProfile.displayName }) })
1125
- ] }, id)) })
1126
- ] }) })
1127
- ] });
1128
- }
1129
- function TeamCreation() {
1130
- const { t } = useTranslation();
1131
- const teamCreationSchema = yupObject({
1132
- displayName: yupString().defined().nonEmpty(t("Please enter a team name"))
1133
- });
1134
- const { register, handleSubmit, formState: { errors } } = useForm({
1135
- resolver: yupResolver(teamCreationSchema)
1136
- });
1137
- const app = useStackApp();
1138
- const project = app.useProject();
1139
- const user = useUser({ or: "redirect" });
1140
- const navigate = app.useNavigate();
1141
- const [loading, setLoading] = useState(false);
1142
- if (!project.config.clientTeamCreationEnabled) {
1143
- return /* @__PURE__ */ jsx(MessageCard, { title: t("Team creation is not enabled") });
1144
- }
1145
- const onSubmit = async (data) => {
1146
- setLoading(true);
1147
- let team;
1148
- try {
1149
- team = await user.createTeam({ displayName: data.displayName });
1150
- } finally {
1151
- setLoading(false);
1152
- }
1153
- navigate(`#team-${team.id}`);
1154
- };
1155
- return /* @__PURE__ */ jsx(PageLayout, { children: /* @__PURE__ */ jsx(Section, { title: t("Create a Team"), description: t("Enter a display name for your new team"), children: /* @__PURE__ */ jsxs(
1156
- "form",
1157
- {
1158
- onSubmit: (e) => runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e)),
1159
- noValidate: true,
1160
- className: "flex gap-2 flex-col sm:flex-row",
1161
- children: [
1162
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
1163
- /* @__PURE__ */ jsx(
1164
- Input,
1165
- {
1166
- id: "displayName",
1167
- type: "text",
1168
- ...register("displayName")
1169
- }
1170
- ),
1171
- /* @__PURE__ */ jsx(FormWarningText, { text: errors.displayName?.message?.toString() })
1172
- ] }),
1173
- /* @__PURE__ */ jsx(Button, { type: "submit", loading, children: t("Create") })
1174
- ]
1175
- }
1176
- ) }) });
1177
- }
1178
- function DeleteAccountSection() {
1179
- const { t } = useTranslation();
1180
- const user = useUser({ or: "redirect" });
1181
- const app = useStackApp();
1182
- const project = app.useProject();
1183
- const [deleting, setDeleting] = useState(false);
1184
- if (!project.config.clientUserDeletionEnabled) {
1185
- return null;
1186
- }
1187
- return /* @__PURE__ */ jsx(
1188
- Section,
1189
- {
1190
- title: t("Delete Account"),
1191
- description: t("Permanently remove your account and all associated data"),
1192
- children: /* @__PURE__ */ jsx("div", { className: "stack-scope flex flex-col items-stretch", children: /* @__PURE__ */ jsx(Accordion, { type: "single", collapsible: true, className: "w-full", children: /* @__PURE__ */ jsxs(AccordionItem, { value: "item-1", children: [
1193
- /* @__PURE__ */ jsx(AccordionTrigger, { children: t("Danger zone") }),
1194
- /* @__PURE__ */ jsx(AccordionContent, { children: !deleting ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
1195
- Button,
1196
- {
1197
- variant: "destructive",
1198
- onClick: () => setDeleting(true),
1199
- children: t("Delete account")
1200
- }
1201
- ) }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
1202
- /* @__PURE__ */ jsx(Typography, { variant: "destructive", children: t("Are you sure you want to delete your account? This action is IRREVERSIBLE and will delete ALL associated data.") }),
1203
- /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
1204
- /* @__PURE__ */ jsx(
1205
- Button,
1206
- {
1207
- variant: "destructive",
1208
- onClick: async () => {
1209
- await user.delete();
1210
- await app.redirectToHome();
1211
- },
1212
- children: t("Delete Account")
1213
- }
1214
- ),
1215
- /* @__PURE__ */ jsx(
1216
- Button,
1217
- {
1218
- variant: "secondary",
1219
- onClick: () => setDeleting(false),
1220
- children: t("Cancel")
1221
- }
1222
- )
1223
- ] })
1224
- ] }) })
1225
- ] }) }) })
1226
- }
1227
- );
1228
- }
1229
- function EditableText(props) {
1230
- const [editing, setEditing] = useState(false);
1231
- const [editingValue, setEditingValue] = useState(props.value);
1232
- const { t } = useTranslation();
1233
- return /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: editing ? /* @__PURE__ */ jsxs(Fragment, { children: [
1234
- /* @__PURE__ */ jsx(
1235
- Input,
1236
- {
1237
- value: editingValue,
1238
- onChange: (e) => setEditingValue(e.target.value)
1239
- }
1240
- ),
1241
- /* @__PURE__ */ jsx(
1242
- Button,
1243
- {
1244
- size: "sm",
1245
- onClick: async () => {
1246
- await props.onSave?.(editingValue);
1247
- setEditing(false);
1248
- },
1249
- children: t("Save")
1250
- }
1251
- ),
1252
- /* @__PURE__ */ jsx(
1253
- Button,
1254
- {
1255
- size: "sm",
1256
- variant: "secondary",
1257
- onClick: () => {
1258
- setEditingValue(props.value);
1259
- setEditing(false);
1260
- },
1261
- children: t("Cancel")
1262
- }
1263
- )
1264
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1265
- /* @__PURE__ */ jsx(Typography, { children: props.value }),
1266
- /* @__PURE__ */ jsx(Button, { onClick: () => setEditing(true), size: "icon", variant: "ghost", children: /* @__PURE__ */ jsx(Edit, { className: "w-4 h-4" }) })
1267
- ] }) });
1268
- }
1269
128
  function ApiKeysPageSkeleton() {
1270
129
  return /* @__PURE__ */ jsxs(PageLayout, { children: [
1271
130
  /* @__PURE__ */ jsx(Skeleton, { className: "h-9 w-full mt-1" }),
@@ -1287,9 +146,6 @@ function TeamCreationSkeleton() {
1287
146
  ] });
1288
147
  }
1289
148
  export {
1290
- AccountSettings,
1291
- ApiKeysPage,
1292
- EditableText,
1293
- TeamApiKeysSection
149
+ AccountSettings
1294
150
  };
1295
151
  //# sourceMappingURL=account-settings.js.map