Line data Source code
1 : import { useDialogStore } from '@/stores/dialogStore'
2 :
3 2356 : const lazyApiNodesSignInContent = () =>
4 : import('@/components/dialog/content/ApiNodesSignInContent.vue')
5 2356 : const lazySignInContent = () =>
6 : import('@/components/dialog/content/SignInContent.vue')
7 2356 : const lazyUpdatePasswordContent = () =>
8 : import('@/components/dialog/content/UpdatePasswordContent.vue')
9 2356 : const lazyComfyOrgHeader = () =>
10 : import('@/components/dialog/header/ComfyOrgHeader.vue')
11 :
12 15653 : export function useAuthDialogs() {
13 15653 : const dialogStore = useDialogStore()
14 :
15 : /**
16 : * Shows a dialog requiring sign in for API nodes
17 : * @returns Promise that resolves to true if user clicks login, false if cancelled
18 : */
19 2 : async function showApiNodesSignInDialog(
20 : apiNodeNames: string[]
21 : ): Promise<boolean> {
22 2 : const { default: ApiNodesSignInContent } = await lazyApiNodesSignInContent()
23 :
24 2 : const key = 'api-nodes-signin'
25 :
26 2 : return new Promise<boolean>((resolve) => {
27 2 : dialogStore.showDialog({
28 : key,
29 : component: ApiNodesSignInContent,
30 : props: {
31 : apiNodeNames,
32 : onLogin: () => showSignInDialog().then((result) => resolve(result)),
33 : onCancel: () => resolve(false)
34 : },
35 : dialogComponentProps: {
36 : headless: true,
37 : closable: true,
38 : onRemoved: () => resolve(false)
39 : }
40 : })
41 : }).then((result) => {
42 2 : dialogStore.closeDialog({ key })
43 2 : return result
44 : })
45 : }
46 :
47 14 : async function showSignInDialog(): Promise<boolean> {
48 14 : const [{ default: SignInContent }, { default: ComfyOrgHeader }] =
49 : await Promise.all([lazySignInContent(), lazyComfyOrgHeader()])
50 :
51 13 : return new Promise<boolean>((resolve) => {
52 13 : dialogStore.showDialog({
53 : key: 'global-signin',
54 : component: SignInContent,
55 : headerComponent: ComfyOrgHeader,
56 : props: {
57 : onSuccess: () => resolve(true)
58 : },
59 : dialogComponentProps: {
60 : size: 'fit',
61 : closable: true,
62 : onRemoved: () => resolve(false)
63 : }
64 : })
65 : }).then((result) => {
66 4 : dialogStore.closeDialog({ key: 'global-signin' })
67 4 : return result
68 : })
69 : }
70 :
71 : /**
72 : * Shows a dialog for updating the current user's password.
73 : */
74 1 : async function showUpdatePasswordDialog() {
75 1 : const [{ default: UpdatePasswordContent }, { default: ComfyOrgHeader }] =
76 : await Promise.all([lazyUpdatePasswordContent(), lazyComfyOrgHeader()])
77 :
78 1 : return dialogStore.showDialog({
79 : key: 'global-update-password',
80 : component: UpdatePasswordContent,
81 : headerComponent: ComfyOrgHeader,
82 : props: {
83 : requestSignIn: showSignInDialog,
84 : onSuccess: () =>
85 : dialogStore.closeDialog({ key: 'global-update-password' })
86 : },
87 : dialogComponentProps: {
88 : size: 'fit'
89 : }
90 : })
91 : }
92 :
93 15653 : return {
94 : showApiNodesSignInDialog,
95 : showSignInDialog,
96 : showUpdatePasswordDialog
97 : }
98 : }
|