import { Button, Code, Paper, Text } from "@mantine/core";
import { notifications } from "@mantine/notifications";
import { Navigate } from "react-router";
import { useUserContext } from "../context/user-context";
import { Layout } from "../components/layouts/layout";
import { ReactNode } from "react";
import { isQueryValid } from "../utils/utils";
import { useAppContext } from "../context/app-context";
export const ContinuePage = () => {
const queryString = window.location.search;
const params = new URLSearchParams(queryString);
const redirectUri = params.get("redirect_uri") ?? "";
const { isLoggedIn } = useUserContext();
const { disableContinue } = useAppContext();
if (!isLoggedIn) {
return ;
}
if (!isQueryValid(redirectUri)) {
return ;
}
const redirect = () => {
notifications.show({
title: "Redirecting",
message: "You should be redirected to the app soon",
color: "blue",
});
setTimeout(() => {
window.location.href = redirectUri;
}, 500);
};
let uri;
try {
uri = new URL(redirectUri);
} catch {
return (
Invalid Redirect
The redirect URL is invalid, please contact the app owner to fix the
issue.
);
}
if (disableContinue) {
window.location.href = redirectUri;
return (
Redirecting
You should be redirected to your app soon.
);
}
if (window.location.protocol === "https:" && uri.protocol === "http:") {
return (
Insecure Redirect
Your are trying to redirect from https to{" "}
http, are you sure you want to continue?
);
}
return (
Continue
Click the button to continue to your app.
);
};
export const ContinuePageLayout = ({ children }: { children: ReactNode }) => {
return (
{children}
);
};