fix: When GCal OAuth Canceled, Do Not Create A Credential (#11987)

pull/11978/head^2
Joe Au-Yeung 2023-10-18 21:35:24 -04:00 committed by GitHub
parent 629629cb9e
commit 1bf56fbe93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -16,10 +16,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { code } = req.query;
const state = decodeOAuthState(req);
if (code && typeof code !== "string") {
if (typeof code !== "string") {
res.status(400).json({ message: "`code` must be a string" });
return;
}
if (!req.session?.user?.id) {
return res.status(401).json({ message: "You must be logged in to do this" });
}
@ -39,7 +40,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (code) {
const token = await oAuth2Client.getToken(code);
key = token.res?.data;
}
await prisma.credential.create({
data: {
@ -49,6 +49,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
appId: "google-calendar",
},
});
}
if (state?.installGoogleVideo) {
const existingGoogleMeetCredential = await prisma.credential.findFirst({