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

Function createApiKey

apps/sim/lib/api-key/auth.ts:54–73  ·  view source on GitHub ↗
(useStorage = true)

Source from the content-addressed store, hash-verified

52 * @returns Promise<{key: string, encryptedKey?: string}> - The plain key and optionally encrypted version
53 */
54export async function createApiKey(useStorage = true): Promise<{
55 key: string
56 encryptedKey?: string
57}> {
58 try {
59 const hasEncryptionKey = env.API_ENCRYPTION_KEY !== undefined
60
61 const plainKey = hasEncryptionKey ? generateEncryptedApiKey() : generateApiKey()
62
63 if (useStorage) {
64 const encryptedKey = await encryptApiKeyForStorage(plainKey)
65 return { key: plainKey, encryptedKey }
66 }
67
68 return { key: plainKey }
69 } catch (error) {
70 logger.error('API key creation error:', { error })
71 throw new Error('Failed to create API key')
72 }
73}
74
75/**
76 * Decrypts an API key from storage for display purposes

Callers 2

route.tsFile · 0.90
createWorkspaceApiKeyFunction · 0.85

Calls 4

generateEncryptedApiKeyFunction · 0.90
generateApiKeyFunction · 0.90
encryptApiKeyForStorageFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected