MCPcopy Index your code
hub / github.com/simstudioai/sim / useCredentialName

Function useCredentialName

apps/sim/hooks/queries/oauth/oauth-credentials.ts:122–184  ·  view source on GitHub ↗
(
  credentialId?: string,
  providerId?: string,
  workflowId?: string,
  workspaceId?: string
)

Source from the content-addressed store, hash-verified

120}
121
122export function useCredentialName(
123 credentialId?: string,
124 providerId?: string,
125 workflowId?: string,
126 workspaceId?: string
127) {
128 // Check if this is a credential set value
129 const isCredentialSet = credentialId?.startsWith(CREDENTIAL_SET.PREFIX) ?? false
130 const credentialSetId = isCredentialSet
131 ? credentialId?.slice(CREDENTIAL_SET.PREFIX.length)
132 : undefined
133
134 // Fetch credential set by ID directly
135 const { data: credentialSetData, isFetching: credentialSetLoading } = useCredentialSetDetail(
136 credentialSetId,
137 isCredentialSet
138 )
139
140 const { data: credentials = [], isFetching: credentialsLoading } = useOAuthCredentials(
141 providerId,
142 {
143 enabled: Boolean(providerId) && !isCredentialSet,
144 workspaceId,
145 workflowId,
146 }
147 )
148
149 const selectedCredential = credentials.find((cred) => cred.id === credentialId)
150
151 const shouldFetchDetail = Boolean(
152 credentialId && !selectedCredential && providerId && workflowId && !isCredentialSet
153 )
154
155 const { data: foreignCredentials = [], isFetching: foreignLoading } = useOAuthCredentialDetail(
156 shouldFetchDetail ? credentialId : undefined,
157 workflowId,
158 shouldFetchDetail
159 )
160
161 // Fallback for credential blocks that have no serviceId/providerId — look up by ID directly
162 const { data: workspaceCredential, isFetching: workspaceCredentialLoading } =
163 useWorkspaceCredential(!providerId && !isCredentialSet ? credentialId : undefined)
164
165 const detailCredential = foreignCredentials[0]
166 const hasForeignMeta = foreignCredentials.length > 0
167
168 const displayName =
169 credentialSetData?.name ??
170 selectedCredential?.name ??
171 detailCredential?.name ??
172 workspaceCredential?.displayName ??
173 null
174
175 return {
176 displayName,
177 isLoading:
178 credentialsLoading ||
179 foreignLoading ||

Callers 1

workflow-block.tsxFile · 0.90

Calls 4

useCredentialSetDetailFunction · 0.90
useWorkspaceCredentialFunction · 0.90
useOAuthCredentialsFunction · 0.85
useOAuthCredentialDetailFunction · 0.85

Tested by

no test coverage detected