Fix onboarding OAuth callback glitch (#1079)

This commit is contained in:
Alex Johansson authored and GitHub committed 2021-11-03 10:47:52 +00:00
1 parent d147772d91
commit a002b194da
7 files changed
+66 -33

No files matched your search

@@ -1,3 +1,4 @@
import type { IntegrationOAuthCallbackState } from "pages/api/integrations/types";
import { useState } from "react";
import { useMutation } from "react-query";
@@ -13,8 +14,14 @@ export default function ConnectIntegration(props: {
}) {
const { type } = props;
const [isLoading, setIsLoading] = useState(false);
const mutation = useMutation(async () => {
const res = await fetch("/api/integrations/" + type.replace("_", "") + "/add");
const state: IntegrationOAuthCallbackState = {
returnTo: location.pathname + location.search,
};
const stateStr = encodeURIComponent(JSON.stringify(state));
const searchParams = `?state=${stateStr}`;
const res = await fetch("/api/integrations/" + type.replace("_", "") + "/add" + searchParams);
if (!res.ok) {
throw new Error("Something went wrong");
}