2
0

🐛 (sheets) Init OAuth client inside a function to avoid potential conflict

This commit is contained in:
Baptiste Arnaud
2023-12-08 15:43:56 +00:00
parent 957eaf33dd
commit 7fcc4fb748

View File

@ -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