Scheduling infrastructure for absolutely everyone.
moving to nextjs/api
Agusti Fernandez Pardob753466bda4c
diff --git a/.eslintrc.js b/.eslintrc.jsnew file mode 100644index 00000000000..0e71ec1eae5--- /dev/null+++ b/.eslintrc.js@@ -0,0 +1 @@+module.exports = require("@calcom/config/eslint-preset");diff --git a/__tests__/event-types.test.ts b/__tests__/event-types.test.tsindex f4c46be3edd..2aea868136c 100644--- a/__tests__/event-types.test.ts+++ b/__tests__/event-types.test.ts@@ -5,6 +5,11 @@ import { EventType } from "@calcom/prisma/client";import handleEvent from "../pages/api/event-types/[id]";+afterAll((done) => {+ prisma.$disconnect().then();+ done();+});+describe("/api/event-types/[id]", () => {it("returns a message with the specified events", async () => {const { req, res } = createMocks({diff --git a/package.json b/package.jsonindex c3b05cc09ee..d305999874a 100644--- a/package.json+++ b/package.json@@ -11,7 +11,7 @@"start": "next start","build": "next build","lint": "next lint",- "test": "jest",+ "test": "jest --detectOpenHandles","type-check": "tsc --pretty --noEmit","clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"},@@ -30,4 +30,4 @@"dependencies": {"next": "^12.1.0"}-}\ No newline at end of file+}diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].tsdeleted file mode 100644index d3d2886b06a..00000000000--- a/pages/api/auth/[...nextauth].ts+++ /dev/null@@ -1,82 +0,0 @@-import { PrismaAdapter } from "@next-auth/prisma-adapter";-import { PrismaClient } from "@prisma/client";-import NextAuth, { NextAuthOptions } from "next-auth";-import EmailProvider from "next-auth/providers/email";--// FIXME: not working when importing prisma directly from our project-// import prisma from "@calcom/prisma";-const prisma = new PrismaClient();--// TODO: get rid of this and do it in it's own auth.cal.com project with a custom Next.js app--export const authOptions: NextAuthOptions = {- // For more information on each option (and a full list of options) go to- // https://next-auth.js.org/configuration/options- adapter: PrismaAdapter(prisma),- // https://next-auth.js.org/configuration/providers- providers: [- EmailProvider({- maxAge: 10 * 60 * 60, // Magic links are valid for 10 min only- // sendVerificationRequest,- }),- ],- secret: process.env.NEXTAUTH_SECRET,- session: {- // Use JSON Web Tokens for session instead of database sessions.- // This option can be used with or without a database for users/accounts.- // Note: `strategy` should be set to 'jwt' if no database is used.-- // TODO: Do we want to move 'database' sessions at some point?- strategy: "jwt",- // Seconds - How long until an idle session expires and is no longer valid.- // maxAge: 30 * 24 * 60 * 60, // 30 days-- // Seconds - Throttle how frequently to write to database to extend a session.- // Use it to limit write operations. Set to 0 to always update the database.- // Note: This option is ignored if using JSON Web Tokens- // updateAge: 24 * 60 * 60, // 24 hours- },-- // JSON Web tokens are only used for sessions if the `strategy: 'jwt'` session- // option is set - or by default if no database is specified.- // https://next-auth.js.org/configuration/options#jwt- jwt: {- // A secret to use for key generation (you should set this explicitly)- secret: process.env.SECRET,- // Set to true to use encryption (default: false)- // encryption: true,- // You can define your own encode/decode functions for signing and encryption- // if you want to override the default behaviour.- // encode: async ({ secret, token, maxAge }) => {},- // decode: async ({ secret, token, maxAge }) => {},- },- // https://next-auth.js.org/configuration/pages- // NOTE: We don't want to enable these, only the API endpoints for auth. We will get rid of this when we do auth.cal.com- pages: {- signIn: "/", // Displays signin buttons- signOut: "/", // Displays form with sign out button- error: "/", // Error code passed in query string as ?error=- verifyRequest: "/", // Used for check email page- newUser: "/", // If set, new users will be directed here on first sign in- },-- // Callbacks are asynchronous functions you can use to control what happens- // when an action is performed.- // https://next-auth.js.org/configuration/callbacks-- callbacks: {- // async signIn({ user, account, profile, email, credentials }) { return true },- // async redirect({ url, baseUrl }) { return baseUrl },- // async session({ session, token, user }) { return session },- // FIXME: add a custom jwt callback, that is stored outside next-auth- // and can be reused to generate valid Personal Access Tokens for the API.- // async jwt({ token, user, account, profile, isNewUser }) { return token }- },-- // Events are useful for logging- // https://next-auth.js.org/configuration/events-- // Enable debug messages in the console if you are having problems- debug: false,-};-export default NextAuth(authOptions);diff --git a/pages/api/me/index.ts b/pages/api/me/index.tsdeleted file mode 100644index 86010001e5e..00000000000--- a/pages/api/me/index.ts+++ /dev/null@@ -1,36 +0,0 @@-import { PrismaClient } from "@prisma/client";-import type { NextApiRequest, NextApiResponse } from "next";-import { getToken } from "next-auth/jwt";--// This local import doesn't work-// import { PrismaClient } from "@calcom/prisma";-const prisma = new PrismaClient();-const secret = process.env.NEXTAUTH_SECRET;--type Data = {- message: string;-};--export default async function me(req: NextApiRequest, res: NextApiResponse<Data>) {- const token = await getToken({ req, secret, raw: false });- console.log("token", token);- if (!token)- return res.status(404).json({- message: `You're not authenticated. Provide a valid Session JWT as Authorization: 'Bearer {your_token_here}'`,- });- if (!token.email)- return res.status(404).json({- message: `Your token doesn't have a valid email`,- });- const email: string | undefined = token?.email;- const user = await prisma.user.findUnique({- where: {- email: email,- },- });- return res.json({- message: `Hello ${user?.name}, your email is ${user?.email}, and your email is ${- user?.emailVerified ? "verified" : "unverified"- }`,- });-}diff --git a/tsconfig.json b/tsconfig.jsonindex b93f1e08a5a..bc4d4d47773 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -4,6 +4,10 @@"node_modules"],"compilerOptions": {+ "lib": ["ES2015"],+ "module": "CommonJS",+ "outDir": "./dist",+ "rootDir": "./","strictNullChecks": true,"baseUrl": "./",},