Skip to content

Commit

Permalink
🐛 (sheets) Init OAuth client inside a function to avoid potential con…
Browse files Browse the repository at this point in the history
…flict
  • Loading branch information
baptisteArno committed Dec 8, 2023
1 parent 957eaf3 commit 7fcc4fb
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions apps/builder/src/lib/googleSheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import prisma from '@typebot.io/lib/prisma'
import { decrypt } from '@typebot.io/lib/api/encryption/decrypt'
import { encrypt } from '@typebot.io/lib/api/encryption/encrypt'

export const oauth2Client = new OAuth2Client(
env.GOOGLE_CLIENT_ID,
env.GOOGLE_CLIENT_SECRET,
`${env.NEXTAUTH_URL}/api/credentials/google-sheets/callback`
)

export const getAuthenticatedGoogleClient = async (
userId: string,
credentialsId: string
): Promise<
{ client: OAuth2Client; credentials: CredentialsFromDb } | undefined
> => {
const oauth2Client = new OAuth2Client(
env.GOOGLE_CLIENT_ID,
env.GOOGLE_CLIENT_SECRET,
`${env.NEXTAUTH_URL}/api/credentials/google-sheets/callback`
)
const credentials = (await prisma.credentials.findFirst({
where: { id: credentialsId, workspace: { members: { some: { userId } } } },
})) as CredentialsFromDb | undefined
Expand Down

0 comments on commit 7fcc4fb

Please sign in to comment.