Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/auth/sign-up.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Layout } from "antd";6import { GetServerSidePropsContext } from "next";7import { useRouter } from "next/router";8import { join } from "path";910import getRequiresToken from "@cocalc/server/auth/tokens/get-requires-token";11import { gtag_id, sign_up_id } from "@cocalc/util/theme";12import SignUp from "components/auth/sign-up";13import Footer from "components/landing/footer";14import Head from "components/landing/head";15import Header from "components/landing/header";16import apiPost from "lib/api/post";17import basePath from "lib/base-path";18import { Customize } from "lib/customize";19import withCustomize from "lib/with-customize";2021export default function SignUpPage({ customize, requiresToken, requireTags }) {22const { siteName, isCommercial } = customize;23const router = useRouter();2425function openRoot() {26router.push("/");27}2829async function onSuccess({ firstFile }) {30if (isCommercial) {31try {32(window as any).gtag?.("event", "conversion", {33send_to: `${gtag_id}/${sign_up_id}`,34event_callback: openRoot,35});36} catch (err) {37console.warn("error sending gtag event", err);38}39}40try {41// If you have at least one project, open the newest one.42const { project_id } = await apiPost("/projects/get-one");43if (project_id) {44let url = join(basePath, `/projects/${project_id}`);45if (firstFile) {46url = join(url, "files", firstFile);47}48window.location.href = url;49}50return;51} catch (_err) {52// no problem -- many situation where wouldn't have a project53}54openRoot();55}5657return (58<Customize value={customize}>59<Head title={`Sign up for ${siteName}`} />60<Layout>61<Header page="sign-up" />62<Layout.Content style={{ backgroundColor: "white" }}>63<SignUp64requiresToken={requiresToken}65onSuccess={onSuccess}66requireTags={requireTags}67/>68<Footer />69</Layout.Content>70</Layout>71</Customize>72);73}7475export async function getServerSideProps(context: GetServerSidePropsContext) {76const customize = await withCustomize({ context });77if (customize.props.customize.account != null) {78// user is already signed in -- redirect them to top level page for now (todo).79const { res } = context;80res.writeHead(302, { location: basePath });81res.end();82return { props: { customize: {} } };83}84customize.props.requiresToken = await getRequiresToken();85// this field only has an effect, if we're on the cocalc.com site.86customize.props.requireTags =87process.env.COCALC_SIGNUP_REQUIRE_TAGS !== "false";88return customize;89}909192