calcom/packages/app-store/stripepayment/api/add.ts
Agusti Fernandez 8bc5a75249
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 <zomars@me.com>

* 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 <git@agusti.me>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Omar López <zomars@me.com>
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
2022-04-21 14:32:25 -06:00

43 lines
1.3 KiB
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
import { stringify } from "querystring";
import { BASE_URL } from "@calcom/lib/constants";
import prisma from "@calcom/prisma";
const client_id = process.env.STRIPE_CLIENT_ID;
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "GET") {
// Get user
const user = await prisma.user.findUnique({
where: {
id: req.session?.user?.id,
},
select: {
email: true,
name: true,
},
});
const redirect_uri = encodeURI(BASE_URL + "/api/integrations/stripepayment/callback");
const stripeConnectParams = {
client_id,
scope: "read_write",
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);
/**
* Choose Express or Standard Stripe accounts
* @url https://stripe.com/docs/connect/accounts
*/
// const url = `https://connect.stripe.com/express/oauth/authorize?${query}`;
const url = `https://connect.stripe.com/oauth/authorize?${query}`;
res.status(200).json({ url });
}
}