Adds banner to Opt-in to V2 UI (#4187)

This commit is contained in:
Omar López authored and GitHub committed 2022-09-05 14:25:21 -06:00
1 parent 49a379ec6c
commit 8653e8eea5
3 files changed
+57 -3

No files matched your search

+11 -3
View File
@@ -4,9 +4,17 @@ import { ensureSession } from "@calcom/lib/auth";
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
async function handler(req: NextApiRequest, res: NextApiResponse<Response>): Promise<void> {
const session = await ensureSession({ req });
/* Only admins can opt-in to V2 for now */
if (session.user.role === "ADMIN") res.setHeader("Set-Cookie", "calcom-v2-early-access=1; Path=/");
// Only logged in users can opt-in/out
await ensureSession({ req });
// If has the cookie, Opt-out of V2
if ("calcom-v2-early-access" in req.cookies && req.cookies["calcom-v2-early-access"] === "1") {
res.setHeader("Set-Cookie", `calcom-v2-early-access=0; Max-Age=0; Path=/`);
} else {
/* Opt-int to V2 */
res.setHeader("Set-Cookie", "calcom-v2-early-access=1; Path=/");
}
res.redirect("/");
}