(params: {
mcpServerId: string
userId: string
workspaceId: string
})
| 70 | } |
| 71 | |
| 72 | export async function getOrCreateOauthRow(params: { |
| 73 | mcpServerId: string |
| 74 | userId: string |
| 75 | workspaceId: string |
| 76 | }): Promise<McpOauthRow> { |
| 77 | const existing = await loadOauthRow(params) |
| 78 | if (existing) return existing |
| 79 | |
| 80 | const id = generateId() |
| 81 | try { |
| 82 | await db.insert(mcpServerOauth).values({ |
| 83 | id, |
| 84 | mcpServerId: params.mcpServerId, |
| 85 | userId: params.userId, |
| 86 | workspaceId: params.workspaceId, |
| 87 | }) |
| 88 | } catch (error) { |
| 89 | const winner = await loadOauthRow(params) |
| 90 | if (winner) return winner |
| 91 | throw error |
| 92 | } |
| 93 | |
| 94 | return { |
| 95 | id, |
| 96 | mcpServerId: params.mcpServerId, |
| 97 | userId: params.userId, |
| 98 | workspaceId: params.workspaceId, |
| 99 | clientInformation: null, |
| 100 | tokens: null, |
| 101 | codeVerifier: null, |
| 102 | state: null, |
| 103 | stateCreatedAt: null, |
| 104 | updatedAt: new Date(), |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | type RawOauthRow = typeof mcpServerOauth.$inferSelect |
| 109 |
no test coverage detected