* Abstract app category navigation * Send key schema to frontend Co-authored-by: Omar López <zomars@users.noreply.github.com> * Render keys for apps on admin * Add enabled col for apps * Save app keys to DB * Add checks for admin role * Abstract setup components * Add AdminAppsList to setup wizard * Migrate to v10 tRPC * Default hide keys * Display enabled apps * Merge branch 'main' into admin-apps-ui * Toggle calendars * WIP * Add params and include AppCategoryNavigation * Refactor getEnabledApps * Add warning for disabling apps * Fallback to cal video when a video app is disabled * WIP send disabled email * Send email to all users of event types with payment app * Disable Stripe when app is disabled * Disable apps in event types * Send email to users on disabled apps * Send email based on what app was disabled * WIP type fix * Disable navigation to apps list if already setup * UI import fixes * Waits for session data before redirecting * Updates admin seeded password To comply with admin password requirements * Update yarn.lock * Flex fixes * Adds admin middleware * Clean up * WIP * WIP * NTS * Add dirName to app metadata * Upsert app if not in db * Upsert app if not in db * Add dirName to app metadata * Add keys to app packages w/ keys * Merge with main * Toggle show keys & on enable * Fix empty keys * Fix lark calendar metadata * Fix some type errors * Fix Lark metadata & check for category when upserting * More type fixes * Fix types & add keys to google cal * WIP * WIP * WIP * More type fixes * Fix type errors * Fix type errors * More type fixes * More type fixes * More type fixes * Feedback * Fixes default value * Feedback * Migrate credential invalid col default value "false" * Upsert app on saving keys * Clean up * Validate app keys on frontend * Add nonempty to app keys schemas * Add web3 * Listlocale filter on categories / category * Grab app metadata via category or categories * Show empty screen if no apps are enabled * Fix type checks * Fix type checks * Fix type checks * Fix type checks * Fix type checks * Fix type checks * Replace .nonempty() w/ .min(1) * Fix type error * Address feedback * Draft Google Meet install button * Add install button and warning dialog * WIP * WIP * Display warning when Meet is selected * Display Google Meet warning on email to organizer * Fix email * Fix type errors * Fix type error * Add connected account component * Add warning message * Address comments * Address feedback * Clean up & add MeetLocationType * Use useApp hook * Translate to new API approach * Remove console.log * Refactor * Fix missing backup Cal video link * WIP * Address feedback * Update submodules * Feedback * Submodule sync Co-authored-by: Omar López <zomars@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Peer Richelsen <peer@cal.com>
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import { google } from "googleapis";
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { WEBAPP_URL, CAL_URL } from "@calcom/lib/constants";
|
|
import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { decodeOAuthState } from "../../_utils/decodeOAuthState";
|
|
import getAppKeysFromSlug from "../../_utils/getAppKeysFromSlug";
|
|
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
|
|
|
let client_id = "";
|
|
let client_secret = "";
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
const { code } = req.query;
|
|
const state = decodeOAuthState(req);
|
|
|
|
if (code && 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" });
|
|
}
|
|
|
|
const appKeys = await getAppKeysFromSlug("google-calendar");
|
|
if (typeof appKeys.client_id === "string") client_id = appKeys.client_id;
|
|
if (typeof appKeys.client_secret === "string") client_secret = appKeys.client_secret;
|
|
if (!client_id) return res.status(400).json({ message: "Google client_id missing." });
|
|
if (!client_secret) return res.status(400).json({ message: "Google client_secret missing." });
|
|
|
|
const redirect_uri = WEBAPP_URL + "/api/integrations/googlecalendar/callback";
|
|
|
|
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uri);
|
|
|
|
let key = "";
|
|
|
|
if (code) {
|
|
const token = await oAuth2Client.getToken(code);
|
|
key = token.res?.data;
|
|
}
|
|
|
|
await prisma.credential.create({
|
|
data: {
|
|
type: "google_calendar",
|
|
key,
|
|
userId: req.session.user.id,
|
|
appId: "google-calendar",
|
|
},
|
|
});
|
|
|
|
if (state?.installGoogleVideo) {
|
|
const existingGoogleMeetCredential = await prisma.credential.findFirst({
|
|
where: {
|
|
userId: req.session.user.id,
|
|
type: "google_video",
|
|
},
|
|
});
|
|
|
|
if (!existingGoogleMeetCredential) {
|
|
await prisma.credential.create({
|
|
data: {
|
|
type: "google_video",
|
|
key: {},
|
|
userId: req.session.user.id,
|
|
appId: "google-meet",
|
|
},
|
|
});
|
|
|
|
res.redirect(
|
|
getSafeRedirectUrl(CAL_URL + "/apps/installed/conferencing?hl=google-meet") ??
|
|
getInstalledAppPath({ variant: "conferencing", slug: "google-meet" })
|
|
);
|
|
}
|
|
}
|
|
res.redirect(
|
|
getSafeRedirectUrl(state?.returnTo) ??
|
|
getInstalledAppPath({ variant: "calendar", slug: "google-calendar" })
|
|
);
|
|
}
|