fix: When GCal OAuth Canceled, Do Not Create A Credential (#11987)
parent
629629cb9e
commit
1bf56fbe93
|
@ -16,10 +16,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
const { code } = req.query;
|
const { code } = req.query;
|
||||||
const state = decodeOAuthState(req);
|
const state = decodeOAuthState(req);
|
||||||
|
|
||||||
if (code && typeof code !== "string") {
|
if (typeof code !== "string") {
|
||||||
res.status(400).json({ message: "`code` must be a string" });
|
res.status(400).json({ message: "`code` must be a string" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.session?.user?.id) {
|
if (!req.session?.user?.id) {
|
||||||
return res.status(401).json({ message: "You must be logged in to do this" });
|
return res.status(401).json({ message: "You must be logged in to do this" });
|
||||||
}
|
}
|
||||||
|
@ -39,16 +40,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
if (code) {
|
if (code) {
|
||||||
const token = await oAuth2Client.getToken(code);
|
const token = await oAuth2Client.getToken(code);
|
||||||
key = token.res?.data;
|
key = token.res?.data;
|
||||||
}
|
|
||||||
|
|
||||||
await prisma.credential.create({
|
await prisma.credential.create({
|
||||||
data: {
|
data: {
|
||||||
type: "google_calendar",
|
type: "google_calendar",
|
||||||
key,
|
key,
|
||||||
userId: req.session.user.id,
|
userId: req.session.user.id,
|
||||||
appId: "google-calendar",
|
appId: "google-calendar",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (state?.installGoogleVideo) {
|
if (state?.installGoogleVideo) {
|
||||||
const existingGoogleMeetCredential = await prisma.credential.findFirst({
|
const existingGoogleMeetCredential = await prisma.credential.findFirst({
|
||||||
|
|
Loading…
Reference in New Issue