2
0

: 🔒️ Investigate on why spreadsheets sometimes fail

This commit is contained in:
Baptiste Arnaud
2022-04-20 10:05:33 -07:00
parent b1759749e4
commit bdd7a1712e
6 changed files with 29 additions and 13 deletions

View File

@ -13,9 +13,11 @@ export const oauth2Client = new OAuth2Client(
export const getAuthenticatedGoogleClient = async (
userId: string,
credentialsId: string
): Promise<OAuth2Client | undefined> => {
const credentials = (await prisma.credentials.findUnique({
where: { id: credentialsId },
): Promise<
{ client: OAuth2Client; credentials: CredentialsFromDb } | undefined
> => {
const credentials = (await prisma.credentials.findFirst({
where: { id: credentialsId, ownerId: userId },
})) as CredentialsFromDb | undefined
if (!credentials || credentials.ownerId !== userId) return
const data = decrypt(
@ -25,7 +27,7 @@ export const getAuthenticatedGoogleClient = async (
oauth2Client.setCredentials(data)
oauth2Client.on('tokens', updateTokens(credentialsId, data))
return oauth2Client
return { client: oauth2Client, credentials }
}
const updateTokens =