mirror of
https://github.com/stonith404/pingvin-share.git
synced 2024-09-20 20:10:36 +02:00
b9f6e3bd08
* Started adding locale translations :) * Added some more translations * Working on translating even more pages * More translations * Added test default locale retrieval * replace `intl.formatMessage` with custom `t` hook * add more translations * improve title syntax * add more translations * translate admin config page * translated error messages * add language selecter * minor fixes * improve language handling * add upcoming languages * add `crowdin.yml` * run formatter --------- Co-authored-by: Steve Tautonico <stautonico@gmail.com>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { LoadingOverlay } from "@mantine/core";
|
|
import { GetServerSidePropsContext } from "next";
|
|
import { useRouter } from "next/router";
|
|
import { useEffect, useState } from "react";
|
|
import SignInForm from "../../components/auth/SignInForm";
|
|
import Meta from "../../components/Meta";
|
|
import useUser from "../../hooks/user.hook";
|
|
import useTranslate from "../../hooks/useTranslate.hook";
|
|
|
|
export function getServerSideProps(context: GetServerSidePropsContext) {
|
|
return {
|
|
props: { redirectPath: context.query.redirect ?? null },
|
|
};
|
|
}
|
|
|
|
const SignIn = ({ redirectPath }: { redirectPath?: string }) => {
|
|
const { refreshUser } = useUser();
|
|
const router = useRouter();
|
|
const t = useTranslate();
|
|
|
|
const [isLoading, setIsLoading] = useState(redirectPath ? true : false);
|
|
|
|
// If the access token is expired, the middleware redirects to this page.
|
|
// If the refresh token is still valid, the user will be redirected to the last page.
|
|
useEffect(() => {
|
|
refreshUser().then((user) => {
|
|
if (user) {
|
|
router.replace(redirectPath ?? "/upload");
|
|
} else {
|
|
setIsLoading(false);
|
|
}
|
|
});
|
|
}, []);
|
|
|
|
if (isLoading) return <LoadingOverlay overlayOpacity={1} visible />;
|
|
|
|
return (
|
|
<>
|
|
<Meta title={t("signin.title")} />
|
|
<SignInForm redirectPath={redirectPath ?? "/upload"} />
|
|
</>
|
|
);
|
|
};
|
|
export default SignIn;
|