🐛 (sheets) Init OAuth client inside a function to avoid potential conflict
This commit is contained in:
@ -7,18 +7,17 @@ import prisma from '@typebot.io/lib/prisma'
|
|||||||
import { decrypt } from '@typebot.io/lib/api/encryption/decrypt'
|
import { decrypt } from '@typebot.io/lib/api/encryption/decrypt'
|
||||||
import { encrypt } from '@typebot.io/lib/api/encryption/encrypt'
|
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 (
|
export const getAuthenticatedGoogleClient = async (
|
||||||
userId: string,
|
userId: string,
|
||||||
credentialsId: string
|
credentialsId: string
|
||||||
): Promise<
|
): Promise<
|
||||||
{ client: OAuth2Client; credentials: CredentialsFromDb } | undefined
|
{ 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({
|
const credentials = (await prisma.credentials.findFirst({
|
||||||
where: { id: credentialsId, workspace: { members: { some: { userId } } } },
|
where: { id: credentialsId, workspace: { members: { some: { userId } } } },
|
||||||
})) as CredentialsFromDb | undefined
|
})) as CredentialsFromDb | undefined
|
||||||
|
Reference in New Issue
Block a user