mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 18:22:40 +00:00
port user ID expose hook from 6786d8e to cloud
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
|
import { whenever } from '@vueuse/core'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
|
||||||
import { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore'
|
import { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore'
|
||||||
import { useCommandStore } from '@/stores/commandStore'
|
import { useCommandStore } from '@/stores/commandStore'
|
||||||
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
|
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
|
||||||
|
import type { AuthUserInfo } from '@/types/authTypes'
|
||||||
|
|
||||||
export const useCurrentUser = () => {
|
export const useCurrentUser = () => {
|
||||||
const authStore = useFirebaseAuthStore()
|
const authStore = useFirebaseAuthStore()
|
||||||
@@ -15,6 +17,27 @@ export const useCurrentUser = () => {
|
|||||||
() => !!isApiKeyLogin.value || firebaseUser.value !== null
|
() => !!isApiKeyLogin.value || firebaseUser.value !== null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const resolvedUserInfo = computed<AuthUserInfo | null>(() => {
|
||||||
|
if (isApiKeyLogin.value && apiKeyStore.currentUser) {
|
||||||
|
return { id: apiKeyStore.currentUser.id }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firebaseUser.value) {
|
||||||
|
return { id: firebaseUser.value.uid }
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
const onUserResolved = (callback: (user: AuthUserInfo) => void) => {
|
||||||
|
if (resolvedUserInfo.value) {
|
||||||
|
callback(resolvedUserInfo.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const stop = whenever(resolvedUserInfo, callback)
|
||||||
|
return () => stop()
|
||||||
|
}
|
||||||
|
|
||||||
const userDisplayName = computed(() => {
|
const userDisplayName = computed(() => {
|
||||||
if (isApiKeyLogin.value) {
|
if (isApiKeyLogin.value) {
|
||||||
return apiKeyStore.currentUser?.name
|
return apiKeyStore.currentUser?.name
|
||||||
@@ -95,7 +118,9 @@ export const useCurrentUser = () => {
|
|||||||
userPhotoUrl,
|
userPhotoUrl,
|
||||||
providerName,
|
providerName,
|
||||||
providerIcon,
|
providerIcon,
|
||||||
|
resolvedUserInfo,
|
||||||
handleSignOut,
|
handleSignOut,
|
||||||
handleSignIn
|
handleSignIn,
|
||||||
|
onUserResolved
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
|
||||||
import { useErrorHandling } from '@/composables/useErrorHandling'
|
import { useErrorHandling } from '@/composables/useErrorHandling'
|
||||||
import { api } from '@/scripts/api'
|
import { api } from '@/scripts/api'
|
||||||
import { app } from '@/scripts/app'
|
import { app } from '@/scripts/app'
|
||||||
@@ -72,6 +73,13 @@ export const useExtensionService = () => {
|
|||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (extension.onAuthUserResolved) {
|
||||||
|
const { onUserResolved } = useCurrentUser()
|
||||||
|
onUserResolved((user) => {
|
||||||
|
void extension.onAuthUserResolved?.(user, app)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,3 +7,7 @@ export type ApiKeyAuthHeader = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type AuthHeader = LoggedInAuthHeader | ApiKeyAuthHeader
|
export type AuthHeader = LoggedInAuthHeader | ApiKeyAuthHeader
|
||||||
|
|
||||||
|
export interface AuthUserInfo {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
|
|||||||
import type { ComfyApp } from '@/scripts/app'
|
import type { ComfyApp } from '@/scripts/app'
|
||||||
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
|
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
|
||||||
import type { ComfyCommand } from '@/stores/commandStore'
|
import type { ComfyCommand } from '@/stores/commandStore'
|
||||||
|
import type { AuthUserInfo } from '@/types/authTypes'
|
||||||
import type { BottomPanelExtension } from '@/types/extensionTypes'
|
import type { BottomPanelExtension } from '@/types/extensionTypes'
|
||||||
import type { SettingParams } from '@/types/settingTypes'
|
import type { SettingParams } from '@/types/settingTypes'
|
||||||
|
|
||||||
@@ -166,5 +167,11 @@ export interface ComfyExtension {
|
|||||||
missingNodeTypes: MissingNodeType[]
|
missingNodeTypes: MissingNodeType[]
|
||||||
): Promise<void> | void
|
): Promise<void> | void
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired whenever authentication resolves, providing the user id.
|
||||||
|
* Extensions can register at any time and will receive the latest value immediately.
|
||||||
|
*/
|
||||||
|
onAuthUserResolved?(user: AuthUserInfo, app: ComfyApp): Promise<void> | void
|
||||||
|
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user