@wow-two-beta/fe-identity 0.0.0-stage → 0.0.2

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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -2
  3. package/dist/chunks/PasswordChangeConfirmationType-xUIFj0b9.js +51 -0
  4. package/dist/chunks/PasswordChangeConfirmationType-xUIFj0b9.js.map +1 -0
  5. package/dist/contracts/AccountInfoDto.d.ts +13 -0
  6. package/dist/contracts/AccountRouteConstants.d.ts +39 -0
  7. package/dist/contracts/ConfirmEmailApiRequest.d.ts +7 -0
  8. package/dist/contracts/EmailAddressApiRequest.d.ts +5 -0
  9. package/dist/contracts/HostedPageRouteConstants.d.ts +27 -0
  10. package/dist/contracts/PasswordChangeApiRequest.d.ts +11 -0
  11. package/dist/contracts/PasswordChangeConfirmationApiRequest.d.ts +5 -0
  12. package/dist/contracts/PasswordChangeConfirmationDto.d.ts +8 -0
  13. package/dist/contracts/PasswordChangeConfirmationType.d.ts +10 -0
  14. package/dist/contracts/PasswordChangeLinkApiRequest.d.ts +7 -0
  15. package/dist/contracts/PasswordChangeRequiredDto.d.ts +13 -0
  16. package/dist/contracts/PhoneSignInApiRequest.d.ts +7 -0
  17. package/dist/contracts/PhoneSignInSendApiRequest.d.ts +5 -0
  18. package/dist/contracts/PhoneSignInSentDto.d.ts +7 -0
  19. package/dist/contracts/RegisterAccountApiRequest.d.ts +9 -0
  20. package/dist/contracts/RegisteredAccountDto.d.ts +7 -0
  21. package/dist/contracts/ResetPasswordApiRequest.d.ts +9 -0
  22. package/dist/contracts/SignInApiRequest.d.ts +7 -0
  23. package/dist/contracts/SignInFieldDto.d.ts +12 -0
  24. package/dist/contracts/SignInMethodDto.d.ts +16 -0
  25. package/dist/contracts/SignInMethodIdConstants.d.ts +7 -0
  26. package/dist/contracts/SignInOptionsDto.d.ts +24 -0
  27. package/dist/contracts/SignInRequirementsDto.d.ts +9 -0
  28. package/dist/contracts/SignInRuleDto.d.ts +12 -0
  29. package/dist/contracts/index.d.ts +24 -0
  30. package/dist/contracts/index.js +40 -0
  31. package/dist/contracts/index.js.map +1 -0
  32. package/dist/kit/account/CreateAccountClient.d.ts +73 -0
  33. package/dist/kit/account/hooks/UseAccountClient.d.ts +10 -0
  34. package/dist/kit/account/hooks/UseAccountForm.d.ts +2 -0
  35. package/dist/kit/account/hooks/UseAccountText.d.ts +7 -0
  36. package/dist/kit/account/hooks/index.d.ts +3 -0
  37. package/dist/kit/account/index.d.ts +2 -0
  38. package/dist/kit/index.d.ts +2 -0
  39. package/dist/kit/index.js +1197 -0
  40. package/dist/kit/index.js.map +1 -0
  41. package/dist/kit/presentation/feedback/failureAlert/FailureAlert.vue.d.ts +7 -0
  42. package/dist/kit/presentation/feedback/failureAlert/index.d.ts +1 -0
  43. package/dist/kit/presentation/forms/changePasswordForm/ChangePasswordForm.vue.d.ts +26 -0
  44. package/dist/kit/presentation/forms/changePasswordForm/ChangePasswordStage.d.ts +12 -0
  45. package/dist/kit/presentation/forms/changePasswordForm/index.d.ts +2 -0
  46. package/dist/kit/presentation/forms/forgotPasswordForm/ForgotPasswordForm.vue.d.ts +19 -0
  47. package/dist/kit/presentation/forms/forgotPasswordForm/index.d.ts +1 -0
  48. package/dist/kit/presentation/forms/index.d.ts +6 -0
  49. package/dist/kit/presentation/forms/passwordSignIn/PasswordSignIn.vue.d.ts +28 -0
  50. package/dist/kit/presentation/forms/passwordSignIn/index.d.ts +1 -0
  51. package/dist/kit/presentation/forms/phoneCodeSignIn/PhoneCodeSignIn.vue.d.ts +25 -0
  52. package/dist/kit/presentation/forms/phoneCodeSignIn/PhoneSignInStep.d.ts +10 -0
  53. package/dist/kit/presentation/forms/phoneCodeSignIn/index.d.ts +2 -0
  54. package/dist/kit/presentation/forms/resetPasswordForm/ResetPasswordForm.vue.d.ts +23 -0
  55. package/dist/kit/presentation/forms/resetPasswordForm/index.d.ts +1 -0
  56. package/dist/kit/presentation/forms/signUpForm/SignUpForm.vue.d.ts +20 -0
  57. package/dist/kit/presentation/forms/signUpForm/index.d.ts +1 -0
  58. package/package.json +59 -4
@@ -0,0 +1,1197 @@
1
+ import { defineComponent, computed, openBlock, createBlock, unref, withCtx, createTextVNode, toDisplayString, createCommentVNode, shallowRef, onMounted, createElementBlock, Fragment, createVNode, createElementVNode } from "vue";
2
+ import { Button } from "@wow-two-beta/fe/presentation/actions";
3
+ import { AlertSimple } from "@wow-two-beta/fe/presentation/feedback";
4
+ import { Field, PasswordInput, TextInput, EmailInput, PhoneInput } from "@wow-two-beta/fe/presentation/forms";
5
+ import { A as AccountRouteConstants, P as PasswordChangeConfirmationType } from "../chunks/PasswordChangeConfirmationType-xUIFj0b9.js";
6
+ import { createApiClient, ApiFailureFactory, ApiFailureExtensions } from "@wow-two-beta/fe/foundation/http";
7
+ import { ResultExtensions, AppErrorType, AppErrorFactory } from "@wow-two-beta/fe/foundation/results";
8
+ import { useLocale } from "@wow-two-beta/fe/foundation/i18n";
9
+ import { useAppForm } from "@wow-two-beta/fe/forms-engine/house";
10
+ const protocolFailure = () => ResultExtensions.fail(ApiFailureFactory.create("protocol"));
11
+ function record(value) {
12
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
13
+ }
14
+ function decodeRegistered(value) {
15
+ const body = record(value);
16
+ if (body && typeof body.userId === "string") {
17
+ return ResultExtensions.ok({ userId: body.userId, isConfirmationSent: body.isConfirmationSent === true });
18
+ }
19
+ return protocolFailure();
20
+ }
21
+ function decodeAccountInfo(value) {
22
+ const body = record(value);
23
+ if (body && typeof body.userId === "string") {
24
+ return ResultExtensions.ok({
25
+ userId: body.userId,
26
+ userName: typeof body.userName === "string" ? body.userName : null,
27
+ email: typeof body.email === "string" ? body.email : null,
28
+ isEmailConfirmed: body.isEmailConfirmed === true,
29
+ isTwoFactorEnabled: body.isTwoFactorEnabled === true
30
+ });
31
+ }
32
+ return protocolFailure();
33
+ }
34
+ const confirmationTypes = Object.values(PasswordChangeConfirmationType);
35
+ function confirmationOf(value) {
36
+ return typeof value === "string" ? confirmationTypes.find((type) => type.toLowerCase() === value.toLowerCase()) : void 0;
37
+ }
38
+ function decodeConfirmation(value) {
39
+ const body = record(value);
40
+ const confirmation = confirmationOf(body?.confirmation);
41
+ if (body && confirmation) return ResultExtensions.ok({ confirmation, isSent: body.isSent === true });
42
+ return protocolFailure();
43
+ }
44
+ function decodeCodeSent(value) {
45
+ const body = record(value);
46
+ if (!body) return protocolFailure();
47
+ const link = typeof body.telegramLinkUrl === "string" && body.telegramLinkUrl.length > 0 ? body.telegramLinkUrl : null;
48
+ return ResultExtensions.ok({ isCodeSent: body.isCodeSent === true, telegramLinkUrl: link });
49
+ }
50
+ function text(value) {
51
+ return typeof value === "string" ? value : null;
52
+ }
53
+ function strings(value) {
54
+ return Array.isArray(value) && value.every((item) => typeof item === "string") ? value : null;
55
+ }
56
+ function list(value, decode) {
57
+ if (!Array.isArray(value)) return null;
58
+ const items = value.map(decode);
59
+ return items.every((item) => item !== null) ? items : null;
60
+ }
61
+ function decodeRule(value) {
62
+ const body = record(value);
63
+ const code = text(body?.code);
64
+ const message = text(body?.message);
65
+ return body && code && message !== null ? { code, params: record(body.params), message } : null;
66
+ }
67
+ function decodeField(value) {
68
+ const body = record(value);
69
+ const name = text(body?.name);
70
+ const kind = text(body?.kind);
71
+ const rules = list(body?.rules, decodeRule);
72
+ return body && name && kind && rules ? { name, kind, countries: strings(body.countries), rules } : null;
73
+ }
74
+ function decodeMethod(value) {
75
+ const body = record(value);
76
+ const id = text(body?.id);
77
+ const fields = list(body?.fields, decodeField);
78
+ if (!body || !id || !fields) return null;
79
+ const passwordRules = body.passwordRules == null ? null : list(body.passwordRules, decodeRule);
80
+ if (body.passwordRules != null && passwordRules === null) return null;
81
+ return { id, channels: strings(body.channels) ?? [], fields, passwordRules };
82
+ }
83
+ function decodeSignInOptions(value) {
84
+ const body = record(value);
85
+ const brandName = text(body?.brandName);
86
+ const theme = text(body?.theme);
87
+ const methods = list(body?.methods, decodeMethod);
88
+ if (!body || !brandName || !theme || !methods) return protocolFailure();
89
+ const requirements = record(body.requirements);
90
+ return ResultExtensions.ok({
91
+ brandName,
92
+ theme,
93
+ backgroundUrl: text(body.backgroundUrl) || null,
94
+ isSignUpEnabled: body.isSignUpEnabled === true,
95
+ locale: text(body.locale) ?? "en",
96
+ locales: strings(body.locales) ?? [],
97
+ methods,
98
+ requirements: {
99
+ isConfirmedEmailRequired: requirements?.isConfirmedEmailRequired === true,
100
+ isConfirmedPhoneNumberRequired: requirements?.isConfirmedPhoneNumberRequired === true,
101
+ isSecondFactorRequired: requirements?.isSecondFactorRequired === true
102
+ }
103
+ });
104
+ }
105
+ function decodeSignedIn(text2) {
106
+ if (text2.trim() === "") return ResultExtensions.ok(null);
107
+ let parsed;
108
+ try {
109
+ parsed = JSON.parse(text2);
110
+ } catch {
111
+ return protocolFailure();
112
+ }
113
+ const outer = record(parsed);
114
+ const body = record(outer?.data) ?? outer;
115
+ if (body?.isPasswordChangeRequired !== true) return body ? ResultExtensions.ok(null) : protocolFailure();
116
+ if (typeof body.ticket !== "string" || body.ticket === "") return protocolFailure();
117
+ return ResultExtensions.ok({
118
+ isPasswordChangeRequired: true,
119
+ confirmation: confirmationOf(body.confirmation) ?? PasswordChangeConfirmationType.None,
120
+ ticket: body.ticket
121
+ });
122
+ }
123
+ function createAccountClient(options = {}) {
124
+ const baseUrl = options.baseUrl?.replace(/\/+$/, "") ?? "";
125
+ const credentials = options.credentials ?? (baseUrl ? "include" : void 0);
126
+ const client = createApiClient({
127
+ baseUrl: `${baseUrl}${AccountRouteConstants.base}`,
128
+ ...credentials !== void 0 ? { credentials } : {},
129
+ ...options.fetch !== void 0 ? { fetch: options.fetch } : {}
130
+ });
131
+ const signInQuery = (clientId) => ({
132
+ [AccountRouteConstants.useCookiesParameter]: true,
133
+ ...clientId ? { [AccountRouteConstants.clientIdParameter]: clientId } : {}
134
+ });
135
+ const send = (path, body, signal) => client.post(path, { body, response: "empty", signal });
136
+ return {
137
+ getSignInOptions: ({ clientId, locale, signal } = {}) => client.get(AccountRouteConstants.signInOptions, {
138
+ query: {
139
+ ...clientId ? { [AccountRouteConstants.clientIdParameter]: clientId } : {},
140
+ ...locale ? { [AccountRouteConstants.localeParameter]: locale } : {}
141
+ },
142
+ signal,
143
+ decode: decodeSignInOptions
144
+ }),
145
+ register: (request, signal) => client.post(AccountRouteConstants.register, { body: request, signal, decode: decodeRegistered }),
146
+ async signIn(request, { clientId, signal } = {}) {
147
+ const answered = await client.post(AccountRouteConstants.login, {
148
+ query: signInQuery(clientId),
149
+ body: request,
150
+ response: "text",
151
+ signal
152
+ });
153
+ return answered.ok ? decodeSignedIn(answered.value) : answered;
154
+ },
155
+ confirmEmail: (request, signal) => client.get(AccountRouteConstants.confirmEmail, { query: { ...request }, response: "empty", signal }),
156
+ resendConfirmationEmail: (request, signal) => send(AccountRouteConstants.resendConfirmationEmail, request, signal),
157
+ forgotPassword: (request, signal) => send(AccountRouteConstants.forgotPassword, request, signal),
158
+ resetPassword: (request, signal) => send(AccountRouteConstants.resetPassword, request, signal),
159
+ getAccountInfo: (signal) => client.get(AccountRouteConstants.manageInfo, { signal, decode: decodeAccountInfo }),
160
+ startPasswordChange: (request, signal) => client.post(AccountRouteConstants.managePasswordConfirmation, {
161
+ body: request ?? {},
162
+ signal,
163
+ decode: decodeConfirmation
164
+ }),
165
+ changePassword: (request, signal) => send(AccountRouteConstants.managePassword, request, signal),
166
+ changePasswordWithLink: (request, signal) => send(AccountRouteConstants.passwordChange, request, signal),
167
+ sendPhoneSignInCode: (request, signal) => client.post(AccountRouteConstants.phoneSignInSend, { body: request, signal, decode: decodeCodeSent }),
168
+ signInWithPhone: (request, { clientId, signal } = {}) => client.post(AccountRouteConstants.phoneSignIn, {
169
+ query: signInQuery(clientId),
170
+ body: request,
171
+ response: "empty",
172
+ signal
173
+ }),
174
+ signOut: (signal) => client.post(AccountRouteConstants.logout, { response: "empty", signal })
175
+ };
176
+ }
177
+ function useAccountClient(source) {
178
+ return source.client ?? createAccountClient(source.baseUrl ? { baseUrl: source.baseUrl } : {});
179
+ }
180
+ function useAccountText() {
181
+ const locale = useLocale();
182
+ return (key, fallback, values) => locale.t(`IdentityKit.${key}`, values, fallback);
183
+ }
184
+ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
185
+ ...{ name: "FailureAlert" },
186
+ __name: "FailureAlert",
187
+ props: {
188
+ failure: {}
189
+ },
190
+ setup(__props) {
191
+ const props = __props;
192
+ const reason = computed(
193
+ () => props.failure && props.failure.type !== AppErrorType.Cancelled ? ApiFailureExtensions.reason(props.failure) : ""
194
+ );
195
+ return (_ctx, _cache) => {
196
+ return reason.value ? (openBlock(), createBlock(unref(AlertSimple), {
197
+ key: 0,
198
+ severity: "danger"
199
+ }, {
200
+ default: withCtx(() => [
201
+ createTextVNode(toDisplayString(reason.value), 1)
202
+ ]),
203
+ _: 1
204
+ })) : createCommentVNode("", true);
205
+ };
206
+ }
207
+ });
208
+ const ChangePasswordStage = {
209
+ /** Refers to the change not started: the instance has not said how it is confirmed. */
210
+ Idle: "idle",
211
+ /** Refers to the change form, with the code field under the `Code` confirmation. */
212
+ Form: "form",
213
+ /** Refers to the `Link` confirmation: only the emailed link opens the form. */
214
+ LinkSent: "link-sent",
215
+ /** Refers to the password changed. */
216
+ Done: "done"
217
+ };
218
+ const _hoisted_1$4 = { class: "flex flex-col gap-4" };
219
+ const _hoisted_2$3 = {
220
+ key: 0,
221
+ class: "text-sm text-muted-foreground"
222
+ };
223
+ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
224
+ ...{ name: "ChangePasswordForm" },
225
+ __name: "ChangePasswordForm",
226
+ props: {
227
+ client: { default: void 0 },
228
+ baseUrl: { default: void 0 },
229
+ token: { default: null },
230
+ ticket: { default: null },
231
+ confirmation: { default: null }
232
+ },
233
+ emits: ["changed"],
234
+ setup(__props, { emit: __emit }) {
235
+ const props = __props;
236
+ const emit = __emit;
237
+ const client = useAccountClient(props);
238
+ const t = useAccountText();
239
+ const isOpenAtOnce = Boolean(props.ticket) && props.confirmation === PasswordChangeConfirmationType.None;
240
+ const stage = shallowRef(
241
+ props.token || isOpenAtOnce ? ChangePasswordStage.Form : ChangePasswordStage.Idle
242
+ );
243
+ const started = shallowRef(
244
+ isOpenAtOnce ? { confirmation: PasswordChangeConfirmationType.None, isSent: false } : null
245
+ );
246
+ const isStarting = shallowRef(false);
247
+ const startFailure = shallowRef(null);
248
+ const isCodeRequired = computed(() => started.value?.confirmation === PasswordChangeConfirmationType.Code);
249
+ const form = useAppForm({
250
+ defaultValues: { currentPassword: "", newPassword: "", code: "" },
251
+ onSubmit: async (values, { signal }) => {
252
+ const result = props.token ? await client.changePasswordWithLink({ token: props.token, newPassword: values.newPassword }, signal) : await client.changePassword(
253
+ {
254
+ ...props.ticket ? { ticket: props.ticket } : { currentPassword: values.currentPassword },
255
+ newPassword: values.newPassword,
256
+ ...isCodeRequired.value ? { code: values.code.trim() } : {}
257
+ },
258
+ signal
259
+ );
260
+ if (result.ok) {
261
+ stage.value = ChangePasswordStage.Done;
262
+ emit("changed");
263
+ }
264
+ return result;
265
+ }
266
+ });
267
+ async function start() {
268
+ isStarting.value = true;
269
+ startFailure.value = null;
270
+ const result = await client.startPasswordChange(props.ticket ? { ticket: props.ticket } : void 0);
271
+ isStarting.value = false;
272
+ if (!result.ok) {
273
+ startFailure.value = result.failure;
274
+ return;
275
+ }
276
+ started.value = result.value;
277
+ stage.value = result.value.confirmation === PasswordChangeConfirmationType.Link ? ChangePasswordStage.LinkSent : ChangePasswordStage.Form;
278
+ }
279
+ onMounted(() => {
280
+ if (props.ticket && !isOpenAtOnce) void start();
281
+ });
282
+ return (_ctx, _cache) => {
283
+ return openBlock(), createElementBlock("div", _hoisted_1$4, [
284
+ __props.ticket && stage.value !== unref(ChangePasswordStage).Done ? (openBlock(), createElementBlock("p", _hoisted_2$3, toDisplayString(unref(t)(
285
+ "ChangePasswordForm.required",
286
+ "Your password no longer meets the rules here. Choose a new one, then sign in with it."
287
+ )), 1)) : createCommentVNode("", true),
288
+ stage.value === unref(ChangePasswordStage).Idle ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
289
+ createVNode(unref(_sfc_main$6), { failure: startFailure.value }, null, 8, ["failure"]),
290
+ createVNode(unref(Button), {
291
+ type: "button",
292
+ "is-full-width": "",
293
+ "is-loading": isStarting.value,
294
+ onClick: start
295
+ }, {
296
+ default: withCtx(() => [
297
+ createTextVNode(toDisplayString(unref(t)("ChangePasswordForm.start", "Change the password")), 1)
298
+ ]),
299
+ _: 1
300
+ }, 8, ["is-loading"])
301
+ ], 64)) : stage.value === unref(ChangePasswordStage).LinkSent ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
302
+ started.value?.isSent ? (openBlock(), createBlock(unref(AlertSimple), {
303
+ key: 0,
304
+ severity: "info"
305
+ }, {
306
+ default: withCtx(() => [
307
+ createTextVNode(toDisplayString(unref(t)("ChangePasswordForm.linkSent", "We sent you a link to change the password. Open it to continue.")), 1)
308
+ ]),
309
+ _: 1
310
+ })) : (openBlock(), createBlock(unref(AlertSimple), {
311
+ key: 1,
312
+ severity: "warning"
313
+ }, {
314
+ default: withCtx(() => [
315
+ createTextVNode(toDisplayString(unref(t)("ChangePasswordForm.linkNotSent", "We could not send the link. Try again in a minute.")), 1)
316
+ ]),
317
+ _: 1
318
+ })),
319
+ createVNode(unref(_sfc_main$6), { failure: startFailure.value }, null, 8, ["failure"]),
320
+ createVNode(unref(Button), {
321
+ type: "button",
322
+ variant: "outline",
323
+ tone: "neutral",
324
+ "is-loading": isStarting.value,
325
+ onClick: start
326
+ }, {
327
+ default: withCtx(() => [
328
+ createTextVNode(toDisplayString(unref(t)("ChangePasswordForm.resendLink", "Send the link again")), 1)
329
+ ]),
330
+ _: 1
331
+ }, 8, ["is-loading"])
332
+ ], 64)) : stage.value === unref(ChangePasswordStage).Form ? (openBlock(), createElementBlock("form", {
333
+ key: 3,
334
+ class: "flex flex-col gap-4",
335
+ novalidate: "",
336
+ onSubmit: _cache[0] || (_cache[0] = //@ts-ignore
337
+ (...args) => unref(form).handleSubmit && unref(form).handleSubmit(...args))
338
+ }, [
339
+ isCodeRequired.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
340
+ started.value?.isSent ? (openBlock(), createBlock(unref(AlertSimple), {
341
+ key: 0,
342
+ severity: "info"
343
+ }, {
344
+ default: withCtx(() => [
345
+ createTextVNode(toDisplayString(unref(t)("ChangePasswordForm.codeSent", "We sent you a code. Enter it beside the new password.")), 1)
346
+ ]),
347
+ _: 1
348
+ })) : (openBlock(), createBlock(unref(AlertSimple), {
349
+ key: 1,
350
+ severity: "warning"
351
+ }, {
352
+ default: withCtx(() => [
353
+ createTextVNode(toDisplayString(unref(t)("ChangePasswordForm.codeNotSent", "We could not send a code. Try again in a minute.")), 1)
354
+ ]),
355
+ _: 1
356
+ }))
357
+ ], 64)) : createCommentVNode("", true),
358
+ !__props.token && !__props.ticket ? (openBlock(), createBlock(unref(form).Field, {
359
+ key: 1,
360
+ name: "currentPassword",
361
+ "is-required": ""
362
+ }, {
363
+ default: withCtx((field) => [
364
+ createVNode(unref(Field), {
365
+ label: unref(t)("ChangePasswordForm.currentPassword", "Current password")
366
+ }, {
367
+ default: withCtx(() => [
368
+ createVNode(unref(PasswordInput), {
369
+ modelValue: field.value,
370
+ "onUpdate:modelValue": ($event) => field.value = $event,
371
+ name: "currentPassword",
372
+ autocomplete: "current-password",
373
+ onBlur: field.onBlur
374
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
375
+ ]),
376
+ _: 2
377
+ }, 1032, ["label"])
378
+ ]),
379
+ _: 1
380
+ })) : createCommentVNode("", true),
381
+ createVNode(unref(form).Field, {
382
+ name: "newPassword",
383
+ "is-required": ""
384
+ }, {
385
+ default: withCtx((field) => [
386
+ createVNode(unref(Field), {
387
+ label: unref(t)("ChangePasswordForm.newPassword", "New password")
388
+ }, {
389
+ default: withCtx(() => [
390
+ createVNode(unref(PasswordInput), {
391
+ modelValue: field.value,
392
+ "onUpdate:modelValue": ($event) => field.value = $event,
393
+ name: "newPassword",
394
+ autocomplete: "new-password",
395
+ onBlur: field.onBlur
396
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
397
+ ]),
398
+ _: 2
399
+ }, 1032, ["label"])
400
+ ]),
401
+ _: 1
402
+ }),
403
+ isCodeRequired.value ? (openBlock(), createBlock(unref(form).Field, {
404
+ key: 2,
405
+ name: "code",
406
+ "is-required": ""
407
+ }, {
408
+ default: withCtx((field) => [
409
+ createVNode(unref(Field), {
410
+ label: unref(t)("ChangePasswordForm.code", "Code")
411
+ }, {
412
+ default: withCtx(() => [
413
+ createVNode(unref(TextInput), {
414
+ modelValue: field.value,
415
+ "onUpdate:modelValue": ($event) => field.value = $event,
416
+ name: "code",
417
+ inputmode: "numeric",
418
+ autocomplete: "one-time-code",
419
+ onBlur: field.onBlur
420
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
421
+ ]),
422
+ _: 2
423
+ }, 1032, ["label"])
424
+ ]),
425
+ _: 1
426
+ })) : createCommentVNode("", true),
427
+ createVNode(unref(_sfc_main$6), {
428
+ failure: unref(form).state.submitError
429
+ }, null, 8, ["failure"]),
430
+ createVNode(unref(_sfc_main$6), { failure: startFailure.value }, null, 8, ["failure"]),
431
+ createVNode(unref(Button), {
432
+ type: "submit",
433
+ "is-full-width": "",
434
+ "is-loading": unref(form).state.isSubmitting
435
+ }, {
436
+ default: withCtx(() => [
437
+ createTextVNode(toDisplayString(unref(t)("ChangePasswordForm.submit", "Change the password")), 1)
438
+ ]),
439
+ _: 1
440
+ }, 8, ["is-loading"]),
441
+ isCodeRequired.value ? (openBlock(), createBlock(unref(Button), {
442
+ key: 3,
443
+ type: "button",
444
+ variant: "ghost",
445
+ tone: "neutral",
446
+ "is-loading": isStarting.value,
447
+ onClick: start
448
+ }, {
449
+ default: withCtx(() => [
450
+ createTextVNode(toDisplayString(unref(t)("ChangePasswordForm.resendCode", "Send a new code")), 1)
451
+ ]),
452
+ _: 1
453
+ }, 8, ["is-loading"])) : createCommentVNode("", true)
454
+ ], 32)) : (openBlock(), createBlock(unref(AlertSimple), {
455
+ key: 4,
456
+ severity: "success"
457
+ }, {
458
+ default: withCtx(() => [
459
+ createTextVNode(toDisplayString(unref(t)("ChangePasswordForm.done", "Your password is changed.")), 1)
460
+ ]),
461
+ _: 1
462
+ }))
463
+ ]);
464
+ };
465
+ }
466
+ });
467
+ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
468
+ ...{ name: "ForgotPasswordForm" },
469
+ __name: "ForgotPasswordForm",
470
+ props: {
471
+ client: { default: void 0 },
472
+ baseUrl: { default: void 0 },
473
+ initialEmail: { default: "" }
474
+ },
475
+ emits: ["sent"],
476
+ setup(__props, { emit: __emit }) {
477
+ const props = __props;
478
+ const emit = __emit;
479
+ const client = useAccountClient(props);
480
+ const t = useAccountText();
481
+ const sentTo = shallowRef(null);
482
+ const form = useAppForm({
483
+ defaultValues: { email: props.initialEmail },
484
+ onSubmit: async (values, { signal }) => {
485
+ const result = await client.forgotPassword(values, signal);
486
+ if (result.ok) {
487
+ sentTo.value = values.email;
488
+ emit("sent", values.email);
489
+ }
490
+ return result;
491
+ }
492
+ });
493
+ return (_ctx, _cache) => {
494
+ return sentTo.value ? (openBlock(), createBlock(unref(AlertSimple), {
495
+ key: 0,
496
+ severity: "success"
497
+ }, {
498
+ default: withCtx(() => [
499
+ createTextVNode(toDisplayString(unref(t)("ForgotPasswordForm.sent", "If an account uses {email}, we sent it a link to reset the password.", {
500
+ email: sentTo.value
501
+ })), 1)
502
+ ]),
503
+ _: 1
504
+ })) : (openBlock(), createElementBlock("form", {
505
+ key: 1,
506
+ class: "flex flex-col gap-4",
507
+ novalidate: "",
508
+ onSubmit: _cache[0] || (_cache[0] = //@ts-ignore
509
+ (...args) => unref(form).handleSubmit && unref(form).handleSubmit(...args))
510
+ }, [
511
+ createVNode(unref(form).Field, {
512
+ name: "email",
513
+ "is-required": ""
514
+ }, {
515
+ default: withCtx((field) => [
516
+ createVNode(unref(Field), {
517
+ label: unref(t)("ForgotPasswordForm.email", "Email")
518
+ }, {
519
+ default: withCtx(() => [
520
+ createVNode(unref(EmailInput), {
521
+ modelValue: field.value,
522
+ "onUpdate:modelValue": ($event) => field.value = $event,
523
+ name: "email",
524
+ autocomplete: "email",
525
+ onBlur: field.onBlur
526
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
527
+ ]),
528
+ _: 2
529
+ }, 1032, ["label"])
530
+ ]),
531
+ _: 1
532
+ }),
533
+ createVNode(unref(_sfc_main$6), {
534
+ failure: unref(form).state.submitError
535
+ }, null, 8, ["failure"]),
536
+ createVNode(unref(Button), {
537
+ type: "submit",
538
+ "is-full-width": "",
539
+ "is-loading": unref(form).state.isSubmitting
540
+ }, {
541
+ default: withCtx(() => [
542
+ createTextVNode(toDisplayString(unref(t)("ForgotPasswordForm.submit", "Send the reset link")), 1)
543
+ ]),
544
+ _: 1
545
+ }, 8, ["is-loading"])
546
+ ], 32));
547
+ };
548
+ }
549
+ });
550
+ const _hoisted_1$3 = ["href"];
551
+ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
552
+ ...{ name: "PasswordSignIn" },
553
+ __name: "PasswordSignIn",
554
+ props: {
555
+ client: { default: void 0 },
556
+ baseUrl: { default: void 0 },
557
+ clientId: { default: null },
558
+ forgotPasswordHref: { default: void 0 },
559
+ initialLogin: { default: "" }
560
+ },
561
+ emits: ["signedIn", "passwordChangeRequired"],
562
+ setup(__props, { emit: __emit }) {
563
+ const props = __props;
564
+ const emit = __emit;
565
+ const client = useAccountClient(props);
566
+ const t = useAccountText();
567
+ const unconfirmedEmail = shallowRef(null);
568
+ const isResent = shallowRef(false);
569
+ const isResending = shallowRef(false);
570
+ const form = useAppForm({
571
+ defaultValues: { login: props.initialLogin, password: "" },
572
+ onSubmit: async (values, { signal }) => {
573
+ unconfirmedEmail.value = null;
574
+ isResent.value = false;
575
+ const result = await client.signIn(values, { clientId: props.clientId, signal });
576
+ if (result.ok) {
577
+ if (result.value) emit("passwordChangeRequired", result.value);
578
+ else emit("signedIn");
579
+ } else if (result.failure.status === 403 && values.login.includes("@")) unconfirmedEmail.value = values.login;
580
+ return result;
581
+ }
582
+ });
583
+ async function resendConfirmation() {
584
+ if (!unconfirmedEmail.value) return;
585
+ isResending.value = true;
586
+ const result = await client.resendConfirmationEmail({ email: unconfirmedEmail.value });
587
+ isResending.value = false;
588
+ isResent.value = result.ok;
589
+ }
590
+ return (_ctx, _cache) => {
591
+ return openBlock(), createElementBlock("form", {
592
+ class: "flex flex-col gap-4",
593
+ novalidate: "",
594
+ onSubmit: _cache[0] || (_cache[0] = //@ts-ignore
595
+ (...args) => unref(form).handleSubmit && unref(form).handleSubmit(...args))
596
+ }, [
597
+ createVNode(unref(form).Field, {
598
+ name: "login",
599
+ "is-required": ""
600
+ }, {
601
+ default: withCtx((field) => [
602
+ createVNode(unref(Field), {
603
+ label: unref(t)("PasswordSignIn.login", "Email or user name")
604
+ }, {
605
+ default: withCtx(() => [
606
+ createVNode(unref(TextInput), {
607
+ modelValue: field.value,
608
+ "onUpdate:modelValue": ($event) => field.value = $event,
609
+ name: "login",
610
+ autocomplete: "username",
611
+ onBlur: field.onBlur
612
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
613
+ ]),
614
+ _: 2
615
+ }, 1032, ["label"])
616
+ ]),
617
+ _: 1
618
+ }),
619
+ createVNode(unref(form).Field, {
620
+ name: "password",
621
+ "is-required": ""
622
+ }, {
623
+ default: withCtx((field) => [
624
+ createVNode(unref(Field), {
625
+ label: unref(t)("PasswordSignIn.password", "Password")
626
+ }, {
627
+ default: withCtx(() => [
628
+ createVNode(unref(PasswordInput), {
629
+ modelValue: field.value,
630
+ "onUpdate:modelValue": ($event) => field.value = $event,
631
+ name: "password",
632
+ autocomplete: "current-password",
633
+ onBlur: field.onBlur
634
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
635
+ ]),
636
+ _: 2
637
+ }, 1032, ["label"])
638
+ ]),
639
+ _: 1
640
+ }),
641
+ __props.forgotPasswordHref ? (openBlock(), createElementBlock("a", {
642
+ key: 0,
643
+ href: __props.forgotPasswordHref,
644
+ class: "-mt-2 self-end text-sm text-primary underline-offset-4 hover:underline"
645
+ }, toDisplayString(unref(t)("PasswordSignIn.forgotPassword", "Forgot your password?")), 9, _hoisted_1$3)) : createCommentVNode("", true),
646
+ createVNode(unref(_sfc_main$6), {
647
+ failure: unref(form).state.submitError
648
+ }, null, 8, ["failure"]),
649
+ unconfirmedEmail.value ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
650
+ isResent.value ? (openBlock(), createBlock(unref(AlertSimple), {
651
+ key: 0,
652
+ severity: "success"
653
+ }, {
654
+ default: withCtx(() => [
655
+ createTextVNode(toDisplayString(unref(t)("PasswordSignIn.confirmationResent", "We sent the confirmation link to {email} again.", {
656
+ email: unconfirmedEmail.value
657
+ })), 1)
658
+ ]),
659
+ _: 1
660
+ })) : (openBlock(), createBlock(unref(Button), {
661
+ key: 1,
662
+ type: "button",
663
+ variant: "outline",
664
+ tone: "neutral",
665
+ "is-loading": isResending.value,
666
+ onClick: resendConfirmation
667
+ }, {
668
+ default: withCtx(() => [
669
+ createTextVNode(toDisplayString(unref(t)("PasswordSignIn.resendConfirmation", "Send the confirmation email again")), 1)
670
+ ]),
671
+ _: 1
672
+ }, 8, ["is-loading"]))
673
+ ], 64)) : createCommentVNode("", true),
674
+ createVNode(unref(Button), {
675
+ type: "submit",
676
+ "is-full-width": "",
677
+ "is-loading": unref(form).state.isSubmitting
678
+ }, {
679
+ default: withCtx(() => [
680
+ createTextVNode(toDisplayString(unref(t)("PasswordSignIn.submit", "Sign in")), 1)
681
+ ]),
682
+ _: 1
683
+ }, 8, ["is-loading"])
684
+ ], 32);
685
+ };
686
+ }
687
+ });
688
+ const PhoneSignInStep = {
689
+ /** Refers to entering the phone a code goes to. */
690
+ Phone: "phone",
691
+ /** Refers to opening the Telegram bot and sharing the contact, after which the bot sends the code. */
692
+ Telegram: "telegram",
693
+ /** Refers to entering the code. */
694
+ Code: "code"
695
+ };
696
+ const _hoisted_1$2 = {
697
+ key: 1,
698
+ class: "flex flex-col gap-4"
699
+ };
700
+ const _hoisted_2$2 = { class: "text-sm text-muted-foreground" };
701
+ const _hoisted_3$1 = ["href"];
702
+ const _hoisted_4 = { class: "text-sm text-muted-foreground" };
703
+ const _hoisted_5 = ["href"];
704
+ const _hoisted_6 = { class: "flex flex-wrap justify-between gap-2" };
705
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
706
+ ...{ name: "PhoneCodeSignIn" },
707
+ __name: "PhoneCodeSignIn",
708
+ props: {
709
+ client: { default: void 0 },
710
+ baseUrl: { default: void 0 },
711
+ clientId: { default: null },
712
+ countries: { default: void 0 },
713
+ defaultCountry: { default: void 0 }
714
+ },
715
+ emits: ["signedIn"],
716
+ setup(__props, { emit: __emit }) {
717
+ const props = __props;
718
+ const emit = __emit;
719
+ const client = useAccountClient(props);
720
+ const t = useAccountText();
721
+ const step = shallowRef(PhoneSignInStep.Phone);
722
+ const phone = shallowRef("");
723
+ const telegramLinkUrl = shallowRef(null);
724
+ const isResending = shallowRef(false);
725
+ const isResent = shallowRef(false);
726
+ const resendFailure = shallowRef(null);
727
+ const notSent = () => ResultExtensions.fail({
728
+ ...AppErrorFactory.unavailable(),
729
+ message: t("PhoneCodeSignIn.notSent", "We could not send a code. Try again in a minute.")
730
+ });
731
+ async function send(value, signal) {
732
+ const result = await client.sendPhoneSignInCode({ phone: value }, signal);
733
+ if (!result.ok) return result;
734
+ if (!result.value.isCodeSent && !result.value.telegramLinkUrl) return notSent();
735
+ phone.value = value;
736
+ telegramLinkUrl.value = result.value.telegramLinkUrl;
737
+ return result;
738
+ }
739
+ const phoneForm = useAppForm({
740
+ defaultValues: { phone: "" },
741
+ onSubmit: async (values, { signal }) => {
742
+ const result = await send(values.phone, signal);
743
+ if (result.ok) {
744
+ codeForm.reset();
745
+ isResent.value = false;
746
+ resendFailure.value = null;
747
+ step.value = telegramLinkUrl.value ? PhoneSignInStep.Telegram : PhoneSignInStep.Code;
748
+ }
749
+ return result;
750
+ }
751
+ });
752
+ const codeForm = useAppForm({
753
+ defaultValues: { code: "" },
754
+ onSubmit: async (values, { signal }) => {
755
+ const result = await client.signInWithPhone(
756
+ { phone: phone.value, code: values.code.trim() },
757
+ { clientId: props.clientId, signal }
758
+ );
759
+ if (result.ok) emit("signedIn");
760
+ return result;
761
+ }
762
+ });
763
+ async function resend() {
764
+ isResending.value = true;
765
+ isResent.value = false;
766
+ resendFailure.value = null;
767
+ const result = await send(phone.value);
768
+ isResending.value = false;
769
+ if (result.ok) isResent.value = true;
770
+ else resendFailure.value = result.failure;
771
+ }
772
+ function useAnotherPhone() {
773
+ step.value = PhoneSignInStep.Phone;
774
+ telegramLinkUrl.value = null;
775
+ }
776
+ return (_ctx, _cache) => {
777
+ return step.value === unref(PhoneSignInStep).Phone ? (openBlock(), createElementBlock("form", {
778
+ key: 0,
779
+ class: "flex flex-col gap-4",
780
+ novalidate: "",
781
+ onSubmit: _cache[0] || (_cache[0] = //@ts-ignore
782
+ (...args) => unref(phoneForm).handleSubmit && unref(phoneForm).handleSubmit(...args))
783
+ }, [
784
+ createVNode(unref(phoneForm).Field, {
785
+ name: "phone",
786
+ "is-required": ""
787
+ }, {
788
+ default: withCtx((field) => [
789
+ createVNode(unref(Field), {
790
+ label: unref(t)("PhoneCodeSignIn.phone", "Phone number")
791
+ }, {
792
+ default: withCtx(() => [
793
+ createVNode(unref(PhoneInput), {
794
+ modelValue: field.value,
795
+ "onUpdate:modelValue": ($event) => field.value = $event,
796
+ name: "phone",
797
+ class: "w-full [&>span]:shrink-0 [&>span]:whitespace-nowrap",
798
+ countries: __props.countries,
799
+ placeholder: unref(t)("PhoneCodeSignIn.phonePlaceholder", ""),
800
+ "default-country": __props.defaultCountry,
801
+ onBlur: field.onBlur
802
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "countries", "placeholder", "default-country", "onBlur"])
803
+ ]),
804
+ _: 2
805
+ }, 1032, ["label"])
806
+ ]),
807
+ _: 1
808
+ }),
809
+ createVNode(unref(_sfc_main$6), {
810
+ failure: unref(phoneForm).state.submitError
811
+ }, null, 8, ["failure"]),
812
+ createVNode(unref(Button), {
813
+ type: "submit",
814
+ "is-full-width": "",
815
+ "is-loading": unref(phoneForm).state.isSubmitting
816
+ }, {
817
+ default: withCtx(() => [
818
+ createTextVNode(toDisplayString(unref(t)("PhoneCodeSignIn.send", "Send a code")), 1)
819
+ ]),
820
+ _: 1
821
+ }, 8, ["is-loading"])
822
+ ], 32)) : step.value === unref(PhoneSignInStep).Telegram ? (openBlock(), createElementBlock("div", _hoisted_1$2, [
823
+ createElementVNode("p", _hoisted_2$2, toDisplayString(unref(t)(
824
+ "PhoneCodeSignIn.telegramIntro",
825
+ "Open our Telegram bot, press Start and share your contact. The bot then sends your code for {phone}.",
826
+ { phone: phone.value }
827
+ )), 1),
828
+ createVNode(unref(Button), {
829
+ "as-child": "",
830
+ "is-full-width": ""
831
+ }, {
832
+ default: withCtx(() => [
833
+ createElementVNode("a", {
834
+ href: telegramLinkUrl.value ?? void 0,
835
+ target: "_blank",
836
+ rel: "noopener noreferrer",
837
+ onClick: _cache[1] || (_cache[1] = ($event) => step.value = unref(PhoneSignInStep).Code)
838
+ }, toDisplayString(unref(t)("PhoneCodeSignIn.openTelegram", "Open Telegram")), 9, _hoisted_3$1)
839
+ ]),
840
+ _: 1
841
+ }),
842
+ createVNode(unref(Button), {
843
+ type: "button",
844
+ variant: "outline",
845
+ tone: "neutral",
846
+ "is-full-width": "",
847
+ onClick: _cache[2] || (_cache[2] = ($event) => step.value = unref(PhoneSignInStep).Code)
848
+ }, {
849
+ default: withCtx(() => [
850
+ createTextVNode(toDisplayString(unref(t)("PhoneCodeSignIn.haveCode", "I have the code")), 1)
851
+ ]),
852
+ _: 1
853
+ }),
854
+ createVNode(unref(Button), {
855
+ type: "button",
856
+ variant: "ghost",
857
+ tone: "neutral",
858
+ onClick: useAnotherPhone
859
+ }, {
860
+ default: withCtx(() => [
861
+ createTextVNode(toDisplayString(unref(t)("PhoneCodeSignIn.otherPhone", "Use another number")), 1)
862
+ ]),
863
+ _: 1
864
+ })
865
+ ])) : (openBlock(), createElementBlock("form", {
866
+ key: 2,
867
+ class: "flex flex-col gap-4",
868
+ novalidate: "",
869
+ onSubmit: _cache[3] || (_cache[3] = //@ts-ignore
870
+ (...args) => unref(codeForm).handleSubmit && unref(codeForm).handleSubmit(...args))
871
+ }, [
872
+ createElementVNode("p", _hoisted_4, [
873
+ telegramLinkUrl.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
874
+ createTextVNode(toDisplayString(unref(t)("PhoneCodeSignIn.codeFromTelegram", "Enter the code the bot sent you in Telegram.")) + " ", 1),
875
+ createElementVNode("a", {
876
+ href: telegramLinkUrl.value,
877
+ target: "_blank",
878
+ rel: "noopener noreferrer",
879
+ class: "text-primary underline-offset-4 hover:underline"
880
+ }, toDisplayString(unref(t)("PhoneCodeSignIn.openTelegramAgain", "Open Telegram")), 9, _hoisted_5)
881
+ ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
882
+ createTextVNode(toDisplayString(unref(t)("PhoneCodeSignIn.codeSent", "We sent a code to {phone}.", { phone: phone.value })), 1)
883
+ ], 64))
884
+ ]),
885
+ createVNode(unref(codeForm).Field, {
886
+ name: "code",
887
+ "is-required": ""
888
+ }, {
889
+ default: withCtx((field) => [
890
+ createVNode(unref(Field), {
891
+ label: unref(t)("PhoneCodeSignIn.code", "Code")
892
+ }, {
893
+ default: withCtx(() => [
894
+ createVNode(unref(TextInput), {
895
+ modelValue: field.value,
896
+ "onUpdate:modelValue": ($event) => field.value = $event,
897
+ name: "code",
898
+ inputmode: "numeric",
899
+ autocomplete: "one-time-code",
900
+ onBlur: field.onBlur
901
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
902
+ ]),
903
+ _: 2
904
+ }, 1032, ["label"])
905
+ ]),
906
+ _: 1
907
+ }),
908
+ createVNode(unref(_sfc_main$6), {
909
+ failure: unref(codeForm).state.submitError
910
+ }, null, 8, ["failure"]),
911
+ createVNode(unref(_sfc_main$6), { failure: resendFailure.value }, null, 8, ["failure"]),
912
+ isResent.value ? (openBlock(), createBlock(unref(AlertSimple), {
913
+ key: 0,
914
+ severity: "success"
915
+ }, {
916
+ default: withCtx(() => [
917
+ createTextVNode(toDisplayString(unref(t)("PhoneCodeSignIn.resent", "We sent a new code.")), 1)
918
+ ]),
919
+ _: 1
920
+ })) : createCommentVNode("", true),
921
+ createVNode(unref(Button), {
922
+ type: "submit",
923
+ "is-full-width": "",
924
+ "is-loading": unref(codeForm).state.isSubmitting
925
+ }, {
926
+ default: withCtx(() => [
927
+ createTextVNode(toDisplayString(unref(t)("PhoneCodeSignIn.submit", "Sign in")), 1)
928
+ ]),
929
+ _: 1
930
+ }, 8, ["is-loading"]),
931
+ createElementVNode("div", _hoisted_6, [
932
+ createVNode(unref(Button), {
933
+ type: "button",
934
+ variant: "ghost",
935
+ tone: "neutral",
936
+ "is-loading": isResending.value,
937
+ onClick: resend
938
+ }, {
939
+ default: withCtx(() => [
940
+ createTextVNode(toDisplayString(unref(t)("PhoneCodeSignIn.resend", "Send a new code")), 1)
941
+ ]),
942
+ _: 1
943
+ }, 8, ["is-loading"]),
944
+ createVNode(unref(Button), {
945
+ type: "button",
946
+ variant: "ghost",
947
+ tone: "neutral",
948
+ onClick: useAnotherPhone
949
+ }, {
950
+ default: withCtx(() => [
951
+ createTextVNode(toDisplayString(unref(t)("PhoneCodeSignIn.otherPhone", "Use another number")), 1)
952
+ ]),
953
+ _: 1
954
+ })
955
+ ])
956
+ ], 32));
957
+ };
958
+ }
959
+ });
960
+ const _hoisted_1$1 = {
961
+ key: 0,
962
+ class: "flex flex-col gap-4"
963
+ };
964
+ const _hoisted_2$1 = ["href"];
965
+ const _hoisted_3 = { class: "text-sm text-muted-foreground" };
966
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
967
+ ...{ name: "ResetPasswordForm" },
968
+ __name: "ResetPasswordForm",
969
+ props: {
970
+ client: { default: void 0 },
971
+ baseUrl: { default: void 0 },
972
+ email: {},
973
+ token: {},
974
+ signInHref: { default: void 0 }
975
+ },
976
+ emits: ["reset"],
977
+ setup(__props, { emit: __emit }) {
978
+ const props = __props;
979
+ const emit = __emit;
980
+ const client = useAccountClient(props);
981
+ const t = useAccountText();
982
+ const isReset = shallowRef(false);
983
+ const form = useAppForm({
984
+ defaultValues: { newPassword: "" },
985
+ onSubmit: async (values, { signal }) => {
986
+ const result = await client.resetPassword(
987
+ { email: props.email, resetToken: props.token, newPassword: values.newPassword },
988
+ signal
989
+ );
990
+ if (result.ok) {
991
+ isReset.value = true;
992
+ emit("reset");
993
+ }
994
+ return result;
995
+ }
996
+ });
997
+ return (_ctx, _cache) => {
998
+ return isReset.value ? (openBlock(), createElementBlock("div", _hoisted_1$1, [
999
+ createVNode(unref(AlertSimple), { severity: "success" }, {
1000
+ default: withCtx(() => [
1001
+ createTextVNode(toDisplayString(unref(t)("ResetPasswordForm.done", "Your password is changed.")), 1)
1002
+ ]),
1003
+ _: 1
1004
+ }),
1005
+ __props.signInHref ? (openBlock(), createBlock(unref(Button), {
1006
+ key: 0,
1007
+ "as-child": "",
1008
+ "is-full-width": ""
1009
+ }, {
1010
+ default: withCtx(() => [
1011
+ createElementVNode("a", { href: __props.signInHref }, toDisplayString(unref(t)("ResetPasswordForm.signIn", "Sign in")), 9, _hoisted_2$1)
1012
+ ]),
1013
+ _: 1
1014
+ })) : createCommentVNode("", true)
1015
+ ])) : (openBlock(), createElementBlock("form", {
1016
+ key: 1,
1017
+ class: "flex flex-col gap-4",
1018
+ novalidate: "",
1019
+ onSubmit: _cache[0] || (_cache[0] = //@ts-ignore
1020
+ (...args) => unref(form).handleSubmit && unref(form).handleSubmit(...args))
1021
+ }, [
1022
+ createElementVNode("p", _hoisted_3, toDisplayString(unref(t)("ResetPasswordForm.intro", "Choose a new password for {email}.", { email: __props.email })), 1),
1023
+ createVNode(unref(form).Field, {
1024
+ name: "newPassword",
1025
+ "is-required": ""
1026
+ }, {
1027
+ default: withCtx((field) => [
1028
+ createVNode(unref(Field), {
1029
+ label: unref(t)("ResetPasswordForm.newPassword", "New password")
1030
+ }, {
1031
+ default: withCtx(() => [
1032
+ createVNode(unref(PasswordInput), {
1033
+ modelValue: field.value,
1034
+ "onUpdate:modelValue": ($event) => field.value = $event,
1035
+ name: "newPassword",
1036
+ autocomplete: "new-password",
1037
+ onBlur: field.onBlur
1038
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
1039
+ ]),
1040
+ _: 2
1041
+ }, 1032, ["label"])
1042
+ ]),
1043
+ _: 1
1044
+ }),
1045
+ createVNode(unref(_sfc_main$6), {
1046
+ failure: unref(form).state.submitError
1047
+ }, null, 8, ["failure"]),
1048
+ createVNode(unref(Button), {
1049
+ type: "submit",
1050
+ "is-full-width": "",
1051
+ "is-loading": unref(form).state.isSubmitting
1052
+ }, {
1053
+ default: withCtx(() => [
1054
+ createTextVNode(toDisplayString(unref(t)("ResetPasswordForm.submit", "Set the password")), 1)
1055
+ ]),
1056
+ _: 1
1057
+ }, 8, ["is-loading"])
1058
+ ], 32));
1059
+ };
1060
+ }
1061
+ });
1062
+ const _hoisted_1 = {
1063
+ key: 0,
1064
+ class: "flex flex-col gap-4"
1065
+ };
1066
+ const _hoisted_2 = ["href"];
1067
+ const _sfc_main = /* @__PURE__ */ defineComponent({
1068
+ ...{ name: "SignUpForm" },
1069
+ __name: "SignUpForm",
1070
+ props: {
1071
+ client: { default: void 0 },
1072
+ baseUrl: { default: void 0 },
1073
+ signInHref: { default: void 0 }
1074
+ },
1075
+ emits: ["signedUp"],
1076
+ setup(__props, { emit: __emit }) {
1077
+ const props = __props;
1078
+ const emit = __emit;
1079
+ const client = useAccountClient(props);
1080
+ const t = useAccountText();
1081
+ const registered = shallowRef(null);
1082
+ const form = useAppForm({
1083
+ defaultValues: { email: "", password: "" },
1084
+ onSubmit: async (values, { signal }) => {
1085
+ const result = await client.register(values, signal);
1086
+ if (result.ok) {
1087
+ registered.value = { account: result.value, email: values.email };
1088
+ emit("signedUp", result.value);
1089
+ }
1090
+ return result;
1091
+ }
1092
+ });
1093
+ return (_ctx, _cache) => {
1094
+ return registered.value ? (openBlock(), createElementBlock("div", _hoisted_1, [
1095
+ createVNode(unref(AlertSimple), { severity: "success" }, {
1096
+ default: withCtx(() => [
1097
+ registered.value.account.isConfirmationSent ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
1098
+ createTextVNode(toDisplayString(unref(t)("SignUpForm.confirmationSent", "Check your inbox: we sent a link to {email} to confirm the address.", {
1099
+ email: registered.value.email
1100
+ })), 1)
1101
+ ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
1102
+ createTextVNode(toDisplayString(unref(t)("SignUpForm.created", "Your account is ready.")), 1)
1103
+ ], 64))
1104
+ ]),
1105
+ _: 1
1106
+ }),
1107
+ __props.signInHref ? (openBlock(), createBlock(unref(Button), {
1108
+ key: 0,
1109
+ "as-child": "",
1110
+ "is-full-width": ""
1111
+ }, {
1112
+ default: withCtx(() => [
1113
+ createElementVNode("a", { href: __props.signInHref }, toDisplayString(unref(t)("SignUpForm.signIn", "Sign in")), 9, _hoisted_2)
1114
+ ]),
1115
+ _: 1
1116
+ })) : createCommentVNode("", true)
1117
+ ])) : (openBlock(), createElementBlock("form", {
1118
+ key: 1,
1119
+ class: "flex flex-col gap-4",
1120
+ novalidate: "",
1121
+ onSubmit: _cache[0] || (_cache[0] = //@ts-ignore
1122
+ (...args) => unref(form).handleSubmit && unref(form).handleSubmit(...args))
1123
+ }, [
1124
+ createVNode(unref(form).Field, {
1125
+ name: "email",
1126
+ "is-required": ""
1127
+ }, {
1128
+ default: withCtx((field) => [
1129
+ createVNode(unref(Field), {
1130
+ label: unref(t)("SignUpForm.email", "Email")
1131
+ }, {
1132
+ default: withCtx(() => [
1133
+ createVNode(unref(EmailInput), {
1134
+ modelValue: field.value,
1135
+ "onUpdate:modelValue": ($event) => field.value = $event,
1136
+ name: "email",
1137
+ autocomplete: "email",
1138
+ onBlur: field.onBlur
1139
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
1140
+ ]),
1141
+ _: 2
1142
+ }, 1032, ["label"])
1143
+ ]),
1144
+ _: 1
1145
+ }),
1146
+ createVNode(unref(form).Field, {
1147
+ name: "password",
1148
+ "is-required": ""
1149
+ }, {
1150
+ default: withCtx((field) => [
1151
+ createVNode(unref(Field), {
1152
+ label: unref(t)("SignUpForm.password", "Password")
1153
+ }, {
1154
+ default: withCtx(() => [
1155
+ createVNode(unref(PasswordInput), {
1156
+ modelValue: field.value,
1157
+ "onUpdate:modelValue": ($event) => field.value = $event,
1158
+ name: "password",
1159
+ autocomplete: "new-password",
1160
+ onBlur: field.onBlur
1161
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onBlur"])
1162
+ ]),
1163
+ _: 2
1164
+ }, 1032, ["label"])
1165
+ ]),
1166
+ _: 1
1167
+ }),
1168
+ createVNode(unref(_sfc_main$6), {
1169
+ failure: unref(form).state.submitError
1170
+ }, null, 8, ["failure"]),
1171
+ createVNode(unref(Button), {
1172
+ type: "submit",
1173
+ "is-full-width": "",
1174
+ "is-loading": unref(form).state.isSubmitting
1175
+ }, {
1176
+ default: withCtx(() => [
1177
+ createTextVNode(toDisplayString(unref(t)("SignUpForm.submit", "Create the account")), 1)
1178
+ ]),
1179
+ _: 1
1180
+ }, 8, ["is-loading"])
1181
+ ], 32));
1182
+ };
1183
+ }
1184
+ });
1185
+ export {
1186
+ _sfc_main$5 as ChangePasswordForm,
1187
+ ChangePasswordStage,
1188
+ _sfc_main$4 as ForgotPasswordForm,
1189
+ _sfc_main$3 as PasswordSignIn,
1190
+ _sfc_main$2 as PhoneCodeSignIn,
1191
+ PhoneSignInStep,
1192
+ _sfc_main$1 as ResetPasswordForm,
1193
+ _sfc_main as SignUpForm,
1194
+ createAccountClient,
1195
+ useAccountText
1196
+ };
1197
+ //# sourceMappingURL=index.js.map