@@ -42,19 +42,47 @@ const error = ref<string | null>(null)
4242const showDeleteModal = ref (false )
4343const isDeleting = ref (false )
4444const deleteError = ref <string | null >(null )
45- const successMessage = ref <string | null >(null )
4645
4746const credentialId = route .params .id as string
4847
49- // Fetch credential details from API
50- async function fetchCredential(): Promise <void > {
51- if (! selectedTeam .value ) return
52-
48+ // Find which team owns the credential by trying each team
49+ async function findCredentialTeam(): Promise <void > {
5350 try {
5451 isLoading .value = true
5552 error .value = null
5653
57- credential .value = await CredentialsService .getCredential (selectedTeam .value .id , credentialId )
54+ const userTeams = await TeamService .getUserTeams ()
55+
56+ if (userTeams .length === 0 ) {
57+ error .value = ' No teams found for user'
58+ return
59+ }
60+
61+ // Try each team to find the one that owns this credential
62+ for (const team of userTeams ) {
63+ try {
64+ const foundCredential = await CredentialsService .getCredential (team .id , credentialId )
65+
66+ // If we successfully found the credential, this is the correct team
67+ credential .value = foundCredential
68+ selectedTeam .value = team
69+ userRole .value = team .role || ' team_user'
70+ return
71+
72+ } catch (err ) {
73+ // If credential not found in this team, continue to next team
74+ if (err instanceof Error && err .message .includes (' not found' )) {
75+ continue
76+ }
77+ // If it's a different error (auth, permissions, etc.), re-throw
78+ throw err
79+ }
80+ }
81+
82+ // If we get here, credential wasn't found in any team
83+ error .value = ' Credential not found in any of your teams'
84+ credential .value = null
85+
5886 } catch (err ) {
5987 error .value = err instanceof Error ? err .message : ' An unknown error occurred'
6088 credential .value = null
@@ -63,25 +91,9 @@ async function fetchCredential(): Promise<void> {
6391 }
6492}
6593
66- // Initialize team context
67- async function initializeTeamContext(): Promise <void > {
68- try {
69- const userTeams = await TeamService .getUserTeams ()
70- if (userTeams .length > 0 ) {
71- selectedTeam .value = userTeams [0 ] // Default to first team
72- userRole .value = selectedTeam .value .role || ' team_user'
73- }
74- } catch (error ) {
75- console .error (' Error initializing team context:' , error )
76- }
77- }
78-
7994// Load data on component mount
8095onMounted (async () => {
81- await initializeTeamContext ()
82- if (selectedTeam .value ) {
83- await fetchCredential ()
84- }
96+ await findCredentialTeam ()
8597})
8698
8799// Computed properties for display
@@ -148,16 +160,14 @@ const confirmDelete = async () => {
148160 // Emit general credentials updated event
149161 eventBus .emit (' credentials-updated' )
150162
151- // Set success message
152- successMessage .value = ` Credential "${credential .value .name }" has been successfully deleted. `
153-
154- // Close modal and navigate back to credentials list
163+ // Close modal and navigate back to credentials list with success message
155164 showDeleteModal .value = false
156165
157- // Navigate back with a slight delay to show success message
158- setTimeout (() => {
159- router .push (' /credentials' )
160- }, 1500 )
166+ // Navigate back with success message in query params
167+ router .push ({
168+ path: ' /credentials' ,
169+ query: { deleted: credential .value .name }
170+ })
161171
162172 } catch (err ) {
163173 console .error (' Error deleting credential:' , err )
@@ -223,14 +233,6 @@ const handleUpdateSecrets = () => {
223233 </DropdownMenu >
224234 </div >
225235
226- <!-- Success Message -->
227- <Alert v-if =" successMessage" class =" mb-4" >
228- <CheckCircle class =" h-4 w-4" />
229- <AlertDescription >
230- {{ successMessage }}
231- </AlertDescription >
232- </Alert >
233-
234236 <!-- Loading State -->
235237 <div v-if =" isLoading" class =" text-muted-foreground" >
236238 {{ t('credentials.detail.loading') }}
0 commit comments