mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-29 05:05:42 +00:00
104 lines
2.6 KiB
TypeScript
104 lines
2.6 KiB
TypeScript
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";
|
|
|
|
export const ContinuePage = () => {
|
|
const queryString = window.location.search;
|
|
const params = new URLSearchParams(queryString);
|
|
const redirectUri = params.get("redirect_uri") ?? "";
|
|
|
|
const { isLoggedIn, disableContinue } = useUserContext();
|
|
|
|
if (!isLoggedIn) {
|
|
return <Navigate to={`/login?redirect_uri=${redirectUri}`} />;
|
|
}
|
|
|
|
if (redirectUri === "null" || redirectUri === "") {
|
|
return <Navigate to="/" />;
|
|
}
|
|
|
|
const redirect = () => {
|
|
notifications.show({
|
|
title: "Redirecting",
|
|
message: "You should be redirected to the app soon",
|
|
color: "blue",
|
|
});
|
|
setTimeout(() => {
|
|
window.location.href = redirectUri;
|
|
}, 500);
|
|
};
|
|
|
|
if (!URL.canParse(redirectUri)) {
|
|
return (
|
|
<ContinuePageLayout>
|
|
<Text size="xl" fw={700}>
|
|
Invalid Redirect
|
|
</Text>
|
|
<Text>
|
|
The redirect URL is invalid, please contact the app owner to fix the
|
|
issue.
|
|
</Text>
|
|
</ContinuePageLayout>
|
|
);
|
|
}
|
|
|
|
const uri = new URL(redirectUri);
|
|
|
|
if (
|
|
window.location.protocol === "https:" &&
|
|
uri.protocol === "http:"
|
|
) {
|
|
return (
|
|
<ContinuePageLayout>
|
|
<Text size="xl" fw={700}>
|
|
Insecure Redirect
|
|
</Text>
|
|
<Text>
|
|
Your are logged in but trying to redirect from <Code>https</Code> to{" "}
|
|
<Code>http</Code>, please click the button to redirect.
|
|
</Text>
|
|
<Button fullWidth mt="xl" onClick={redirect}>
|
|
Continue
|
|
</Button>
|
|
</ContinuePageLayout>
|
|
);
|
|
}
|
|
|
|
if (disableContinue) {
|
|
window.location.href = redirectUri;
|
|
return (
|
|
<ContinuePageLayout>
|
|
<Text size="xl" fw={700}>
|
|
Redirecting
|
|
</Text>
|
|
<Text>You should be redirected to your app soon.</Text>
|
|
</ContinuePageLayout>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<ContinuePageLayout>
|
|
<Text size="xl" fw={700}>
|
|
Continue
|
|
</Text>
|
|
<Text>Click the button to continue to your app.</Text>
|
|
<Button fullWidth mt="xl" onClick={redirect}>
|
|
Continue
|
|
</Button>
|
|
</ContinuePageLayout>
|
|
);
|
|
};
|
|
|
|
export const ContinuePageLayout = ({ children }: { children: ReactNode }) => {
|
|
return (
|
|
<Layout>
|
|
<Paper shadow="md" p={30} mt={30} radius="md" withBorder>
|
|
{children}
|
|
</Paper>
|
|
</Layout>
|
|
);
|
|
};
|