11import { db } from '@sim/db'
2- import { account , credential , credentialMember , user } from '@sim/db/schema'
2+ import { account , credential , credentialMember } from '@sim/db/schema'
33import { createLogger } from '@sim/logger'
44import { and , eq } from 'drizzle-orm'
5- import { jwtDecode } from 'jwt-decode'
65import { type NextRequest , NextResponse } from 'next/server'
76import { z } from 'zod'
87import { checkSessionOrInternalAuth } from '@/lib/auth/hybrid'
98import { generateRequestId } from '@/lib/core/utils/request'
109import { syncWorkspaceOAuthCredentialsForUser } from '@/lib/credentials/oauth'
11- import { evaluateScopeCoverage , type OAuthProvider , parseProvider } from '@/lib/oauth'
10+ import { evaluateScopeCoverage } from '@/lib/oauth'
1211import { authorizeWorkflowByWorkspacePermission } from '@/lib/workflows/utils'
1312import { checkWorkspaceAccess } from '@/lib/workspaces/permissions/utils'
1413
@@ -32,12 +31,6 @@ const credentialsQuerySchema = z
3231 path : [ 'provider' ] ,
3332 } )
3433
35- interface GoogleIdToken {
36- email ?: string
37- sub ?: string
38- name ?: string
39- }
40-
4134function toCredentialResponse (
4235 id : string ,
4336 displayName : string ,
@@ -64,53 +57,6 @@ function toCredentialResponse(
6457 }
6558}
6659
67- async function getFallbackDisplayName (
68- requestId : string ,
69- providerParam : string | null | undefined ,
70- accountRow : {
71- idToken : string | null
72- accountId : string
73- userId : string
74- }
75- ) {
76- const providerForParse = ( providerParam || 'google' ) as OAuthProvider
77- const { baseProvider } = parseProvider ( providerForParse )
78-
79- if ( accountRow . idToken ) {
80- try {
81- const decoded = jwtDecode < GoogleIdToken > ( accountRow . idToken )
82- if ( decoded . email ) return decoded . email
83- if ( decoded . name ) return decoded . name
84- } catch ( _error ) {
85- logger . warn ( `[${ requestId } ] Error decoding ID token` , {
86- accountId : accountRow . accountId ,
87- } )
88- }
89- }
90-
91- if ( baseProvider === 'github' ) {
92- return `${ accountRow . accountId } (GitHub)`
93- }
94-
95- try {
96- const userRecord = await db
97- . select ( { email : user . email } )
98- . from ( user )
99- . where ( eq ( user . id , accountRow . userId ) )
100- . limit ( 1 )
101-
102- if ( userRecord . length > 0 ) {
103- return userRecord [ 0 ] . email
104- }
105- } catch ( _error ) {
106- logger . warn ( `[${ requestId } ] Error fetching user email` , {
107- userId : accountRow . userId ,
108- } )
109- }
110-
111- return `${ accountRow . accountId } (${ baseProvider } )`
112- }
113-
11460/**
11561 * Get credentials for a specific provider
11662 */
@@ -193,8 +139,6 @@ export async function GET(request: NextRequest) {
193139 }
194140 }
195141
196- let accountsData
197-
198142 if ( credentialId ) {
199143 const [ platformCredential ] = await db
200144 . select ( {
@@ -303,29 +247,7 @@ export async function GET(request: NextRequest) {
303247 )
304248 }
305249
306- if ( credentialId && workflowId ) {
307- accountsData = await db . select ( ) . from ( account ) . where ( eq ( account . id , credentialId ) )
308- } else if ( credentialId ) {
309- accountsData = await db
310- . select ( )
311- . from ( account )
312- . where ( and ( eq ( account . userId , requesterUserId ) , eq ( account . id , credentialId ) ) )
313- } else {
314- accountsData = await db
315- . select ( )
316- . from ( account )
317- . where ( and ( eq ( account . userId , requesterUserId ) , eq ( account . providerId , providerParam ! ) ) )
318- }
319-
320- // Transform accounts into credentials
321- const credentials = await Promise . all (
322- accountsData . map ( async ( acc ) => {
323- const displayName = await getFallbackDisplayName ( requestId , providerParam , acc )
324- return toCredentialResponse ( acc . id , displayName , acc . providerId , acc . updatedAt , acc . scope )
325- } )
326- )
327-
328- return NextResponse . json ( { credentials } , { status : 200 } )
250+ return NextResponse . json ( { credentials : [ ] } , { status : 200 } )
329251 } catch ( error ) {
330252 logger . error ( `[${ requestId } ] Error fetching OAuth credentials` , error )
331253 return NextResponse . json ( { error : 'Internal server error' } , { status : 500 } )
0 commit comments