Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/auth/sign-up.tsx
6077 views
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Layout } from "antd";
7
import { GetServerSidePropsContext } from "next";
8
import { useRouter } from "next/router";
9
10
import getRequiresToken from "@cocalc/server/auth/tokens/get-requires-token";
11
import { gtag_id, sign_up_id } from "@cocalc/util/theme";
12
import SignUp from "components/auth/sign-up";
13
import Footer from "components/landing/footer";
14
import Head from "components/landing/head";
15
import Header from "components/landing/header";
16
import basePath from "lib/base-path";
17
import { Customize } from "lib/customize";
18
import withCustomize from "lib/with-customize";
19
20
export default function SignUpPage({ customize, requiresToken, requireTags }) {
21
const { siteName, isCommercial } = customize;
22
const router = useRouter();
23
24
function openRoot() {
25
router.push("/");
26
}
27
28
async function onSuccess() {
29
if (isCommercial) {
30
try {
31
(window as any).gtag?.("event", "conversion", {
32
send_to: `${gtag_id}/${sign_up_id}`,
33
event_callback: openRoot,
34
});
35
} catch (err) {
36
console.warn("error sending gtag event", err);
37
}
38
}
39
router.push("/app?sign-in");
40
}
41
42
return (
43
<Customize value={customize}>
44
<Head title={`Sign up for ${siteName}`} />
45
<Layout>
46
<Header page="sign-up" />
47
<Layout.Content style={{ backgroundColor: "white" }}>
48
<SignUp
49
requiresToken={requiresToken}
50
onSuccess={onSuccess}
51
requireTags={requireTags}
52
/>
53
<Footer />
54
</Layout.Content>
55
</Layout>
56
</Customize>
57
);
58
}
59
60
export async function getServerSideProps(context: GetServerSidePropsContext) {
61
const customize = await withCustomize({ context });
62
if (customize.props.customize.account != null) {
63
// user is already signed in -- redirect them to top level page for now (todo).
64
const { res } = context;
65
res.writeHead(302, { location: basePath });
66
res.end();
67
return { props: { customize: {} } };
68
}
69
customize.props.requiresToken = await getRequiresToken();
70
// this field only has an effect, if we're on the cocalc.com site.
71
customize.props.requireTags =
72
process.env.COCALC_SIGNUP_REQUIRE_TAGS !== "false";
73
return customize;
74
}
75
76