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

Function safeAccountInsert

apps/sim/app/api/auth/oauth/utils.ts:276–293  ·  view source on GitHub ↗
(
  data: AccountInsertData,
  context: { provider: string; identifier?: string }
)

Source from the content-addressed store, hash-verified

274 * If a duplicate is detected (unique constraint violation), logs a warning and returns success.
275 */
276export async function safeAccountInsert(
277 data: AccountInsertData,
278 context: { provider: string; identifier?: string }
279): Promise<void> {
280 try {
281 await db.insert(account).values(data)
282 logger.info(`Created new ${context.provider} account for user`, { userId: data.userId })
283 } catch (error: any) {
284 if (error?.code === '23505') {
285 logger.error(`Duplicate ${context.provider} account detected, credential already exists`, {
286 userId: data.userId,
287 identifier: context.identifier,
288 })
289 } else {
290 throw error
291 }
292 }
293}
294
295/**
296 * Get a credential by resolved account ID and verify it belongs to the user.

Callers 2

route.tsFile · 0.90
route.tsFile · 0.90

Calls 2

infoMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected