feat: Signup query params tracking (#2098)

* feat: Add tracking of signup query params

* fix: Headers already sent to client

* fix: OAuth error wipes previously written query params cookie
This commit is contained in:
Tom Moor
2021-05-01 13:46:08 -07:00
committed by GitHub
parent 4d68a34897
commit 77d6adb73b
6 changed files with 67 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import { BackIcon, EmailIcon } from "outline-icons";
import * as React from "react";
import { Redirect, Link, type Location } from "react-router-dom";
import styled from "styled-components";
import { setCookie } from "tiny-cookie";
import ButtonLarge from "components/ButtonLarge";
import Fade from "components/Fade";
import Flex from "components/Flex";
@@ -16,6 +17,7 @@ import TeamLogo from "components/TeamLogo";
import Notices from "./Notices";
import Provider from "./Provider";
import env from "env";
import useQuery from "hooks/useQuery";
import useStores from "hooks/useStores";
type Props = {|
@@ -23,6 +25,7 @@ type Props = {|
|};
function Login({ location }: Props) {
const query = useQuery();
const { auth } = useStores();
const { config } = auth;
const [emailLinkSentTo, setEmailLinkSentTo] = React.useState("");
@@ -40,6 +43,17 @@ function Login({ location }: Props) {
auth.fetchConfig();
}, [auth]);
React.useEffect(() => {
const entries = Object.fromEntries(query.entries());
// We don't want to override this cookie if we're viewing an error notice
// sent back from the server via query string (notice=), or if there are no
// query params at all.
if (Object.keys(entries).length && !query.get("notice")) {
setCookie("signupQueryParams", JSON.stringify(entries));
}
}, [query]);
if (auth.authenticated) {
return <Redirect to="/home" />;
}