mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-21 23:34:31 +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 { useApiKeyAuthStore } from '@/stores/apiKeyAuthStore'
|
||||
import { useCommandStore } from '@/stores/commandStore'
|
||||
import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore'
|
||||
import type { AuthUserInfo } from '@/types/authTypes'
|
||||
|
||||
export const useCurrentUser = () => {
|
||||
const authStore = useFirebaseAuthStore()
|
||||
@@ -15,6 +17,27 @@ export const useCurrentUser = () => {
|
||||
() => !!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(() => {
|
||||
if (isApiKeyLogin.value) {
|
||||
return apiKeyStore.currentUser?.name
|
||||
@@ -95,7 +118,9 @@ export const useCurrentUser = () => {
|
||||
userPhotoUrl,
|
||||
providerName,
|
||||
providerIcon,
|
||||
resolvedUserInfo,
|
||||
handleSignOut,
|
||||
handleSignIn
|
||||
handleSignIn,
|
||||
onUserResolved
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user