Feature: Verify login on signup with magic link. (#2122)
* manual migration to rename verificationtoken, maybe it could be dropped and create a new table instead if we're not using it, will consult @zomars * feat: rename verificationRequest --> verificationToken in schema.prisma * fix: rename verificationRequest -> verificationToken in the codebase * feat: add default cookies for next-auth * fix: moves @lib/serverConfig to @calcom/lib so it can be called by website too * fix: make self-certificate work in dev env by not rejecting tls in serverConfig * fix verificationTokenToken typo Co-authored-by: Omar López <[email protected]> * Adds domain: .cal.com if not dev env in cookies * Adds default-cookies to apps/web, and nextauth_domain to turbo website build deps"a * update NEXTAUTH_DOMAIN to NEXTAUTH_COOKIE_DOMAIN * Updates website submodule * Removes deprecated env vars * Consolidates auth logic in one place * Updates website module * Signup fixes * Build fixes * Updates example * Updates example * Fixes * Fix Email Verification * fix: move csrf-token cookiePrefix from __Host -> __Secure * Removes console log * Fixes link in email template * Removed irrelevant coment * Testing with a 32 bit secret * Fixes for cookien in E2E * E2E fixes * Fixes Stripe tests locally * Temp fix for E2E Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Omar López <[email protected]> Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
30 files changed
+957
-52
No files matched your search
@@ -26,6 +26,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
response_type: "code",
|
||||
"stripe_user[email]": user?.email,
|
||||
"stripe_user[first_name]": user?.name,
|
||||
/** We need this so E2E don't fail for international users */
|
||||
"stripe_user[country]": process.env.NEXT_PUBLIC_IS_E2E ? "US" : undefined,
|
||||
redirect_uri,
|
||||
};
|
||||
const query = stringify(stripeConnectParams);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { CookiesOptions } from "next-auth";
|
||||
|
||||
import { isENVDev } from "@calcom/lib/env";
|
||||
|
||||
/**
|
||||
* Copy from 'https://github.com/nextauthjs/next-auth/blob/227ff2259f/src/core/lib/cookie.ts' as we can't import it directly
|
||||
*
|
||||
* Use secure cookies if the site uses HTTPS
|
||||
* This being conditional allows cookies to work non-HTTPS development URLs
|
||||
* Honour secure cookie option, which sets 'secure' and also adds '__Secure-'
|
||||
* prefix, but enable them by default if the site URL is HTTPS; but not for
|
||||
* non-HTTPS URLs like http://localhost which are used in development).
|
||||
* For more on prefixes see https://googlechrome.github.io/samples/cookie-prefixes/
|
||||
*
|
||||
*/
|
||||
|
||||
const NEXTAUTH_COOKIE_DOMAIN = process.env.NEXTAUTH_COOKIE_DOMAIN || "";
|
||||
export function defaultCookies(useSecureCookies: boolean): CookiesOptions {
|
||||
const cookiePrefix = useSecureCookies ? "__Secure-" : "";
|
||||
|
||||
const defaultOptions = {
|
||||
domain: isENVDev ? undefined : NEXTAUTH_COOKIE_DOMAIN,
|
||||
// To enable cookies on widgets,
|
||||
// https://stackoverflow.com/questions/45094712/iframe-not-reading-cookies-in-chrome
|
||||
// But we need to set it as `lax` in development
|
||||
sameSite: useSecureCookies ? "none" : "lax",
|
||||
path: "/",
|
||||
secure: useSecureCookies,
|
||||
};
|
||||
return {
|
||||
sessionToken: {
|
||||
name: `${cookiePrefix}next-auth.session-token`,
|
||||
options: {
|
||||
...defaultOptions,
|
||||
httpOnly: true,
|
||||
},
|
||||
},
|
||||
callbackUrl: {
|
||||
name: `${cookiePrefix}next-auth.callback-url`,
|
||||
options: defaultOptions,
|
||||
},
|
||||
csrfToken: {
|
||||
name: `${cookiePrefix}next-auth.csrf-token`,
|
||||
options: {
|
||||
...defaultOptions,
|
||||
httpOnly: true,
|
||||
},
|
||||
},
|
||||
pkceCodeVerifier: {
|
||||
name: `${cookiePrefix}next-auth.pkce.code_verifier`,
|
||||
options: {
|
||||
...defaultOptions,
|
||||
httpOnly: true,
|
||||
},
|
||||
},
|
||||
state: {
|
||||
name: `${cookiePrefix}next-auth.state`,
|
||||
options: {
|
||||
...defaultOptions,
|
||||
httpOnly: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export const isENVProd = process.env.NODE_ENV === "production";
|
||||
export const isENVDev = process.env.NODE_ENV === "development";
|
||||
@@ -0,0 +1,39 @@
|
||||
import SendmailTransport from "nodemailer/lib/sendmail-transport";
|
||||
import SMTPConnection from "nodemailer/lib/smtp-connection";
|
||||
|
||||
import { isENVDev } from "@calcom/lib/env";
|
||||
|
||||
function detectTransport(): SendmailTransport.Options | SMTPConnection.Options | string {
|
||||
if (process.env.EMAIL_SERVER) {
|
||||
return process.env.EMAIL_SERVER;
|
||||
}
|
||||
|
||||
if (process.env.EMAIL_SERVER_HOST) {
|
||||
const port = parseInt(process.env.EMAIL_SERVER_PORT!);
|
||||
const transport = {
|
||||
host: process.env.EMAIL_SERVER_HOST,
|
||||
port,
|
||||
auth: {
|
||||
user: process.env.EMAIL_SERVER_USER,
|
||||
pass: process.env.EMAIL_SERVER_PASSWORD,
|
||||
},
|
||||
secure: port === 465,
|
||||
tls: {
|
||||
rejectUnauthorized: isENVDev ? false : true,
|
||||
},
|
||||
};
|
||||
|
||||
return transport;
|
||||
}
|
||||
|
||||
return {
|
||||
sendmail: true,
|
||||
newline: "unix",
|
||||
path: "/usr/sbin/sendmail",
|
||||
};
|
||||
}
|
||||
|
||||
export const serverConfig = {
|
||||
transport: detectTransport(),
|
||||
from: process.env.EMAIL_FROM,
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
ALTER TABLE IF EXISTS "VerificationRequest" RENAME TO "VerificationToken";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX IF EXISTS "VerificationRequest_pkey" RENAME TO "VerificationToken_pkey";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX IF EXISTS "VerificationRequest_token_key" RENAME TO "VerificationToken_token_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX IF EXISTS "VerificationRequest_identifier_token_key" RENAME TO "VerificationToken_identifier_token_key";
|
||||
@@ -0,0 +1,5 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "BookingReference" DROP CONSTRAINT "BookingReference_bookingId_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BookingReference" ADD CONSTRAINT "BookingReference_bookingId_fkey" FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
-- RenameIndex
|
||||
ALTER INDEX IF EXISTS "VerificationRequest.identifier_token_unique" RENAME TO "VerificationToken_identifier_token_key";
|
||||
|
||||
-- RenameIndex
|
||||
ALTER INDEX IF EXISTS "VerificationRequest.token_unique" RENAME TO "VerificationToken_token_key";
|
||||
@@ -27,7 +27,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@calcom/lib": "*",
|
||||
"@prisma/client": "3.10.0"
|
||||
"@prisma/client": "^3.12.0"
|
||||
},
|
||||
"main": "index.ts",
|
||||
"types": "index.d.ts",
|
||||
|
||||
@@ -188,7 +188,7 @@ model Membership {
|
||||
@@id([userId, teamId])
|
||||
}
|
||||
|
||||
model VerificationRequest {
|
||||
model VerificationToken {
|
||||
id Int @id @default(autoincrement())
|
||||
identifier String
|
||||
token String @unique
|
||||
|
||||
Vendored
+1
-1
@@ -19,7 +19,7 @@ declare namespace NodeJS {
|
||||
readonly NEXT_PUBLIC_BASE_URL: string | undefined;
|
||||
/** @deprecated use `NEXT_PUBLIC_WEBSITE_URL` */
|
||||
readonly NEXT_PUBLIC_APP_URL: string | undefined;
|
||||
readonly JWT_SECRET: string | undefined;
|
||||
readonly NEXTAUTH_SECRET: string | undefined;
|
||||
readonly NEXT_PUBLIC_TELEMETRY_KEY: string | undefined;
|
||||
readonly MS_GRAPH_CLIENT_ID: string | undefined;
|
||||
readonly MS_GRAPH_CLIENT_SECRET: string | undefined;
|
||||
|
||||
Reference in new issue
Block a user