Fixes adding google integration not appearing in the dashboard after adding it. This was due to the credential being added async and the redirect happened before the save has completed.

pull/89/head
Alex van Andel 2021-04-22 11:09:18 +00:00
parent ce398bd77c
commit 598a86426b
1 changed files with 5 additions and 6 deletions

View File

@ -27,9 +27,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
// Convert to token
oAuth2Client.getToken(code, async (err, token) => {
return new Promise( (resolve, reject) => oAuth2Client.getToken(code, async (err, token) => {
if (err) return console.error('Error retrieving access token', err);
const credential = await prisma.credential.create({
data: {
type: 'google_calendar',
@ -37,9 +37,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
userId: user.id
}
});
});
// Add the credential
res.redirect('/integrations');
res.redirect('/integrations');
resolve();
}));
}