Created a system to go directly to an assignment from a URL
This commit is contained in:
@@ -20,16 +20,17 @@ import { redirect } from "@/utils";
|
||||
|
||||
const EMAIL_REGEX = new RegExp(/^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*$/g);
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
export const getServerSideProps = withIronSessionSsr(async ({req, res, query}) => {
|
||||
const destination = !query.destination ? "/" : Buffer.from(query.destination as string, 'base64').toString()
|
||||
const user = await requestUser(req, res)
|
||||
if (user) return redirect("/")
|
||||
if (user) return redirect(destination)
|
||||
|
||||
return {
|
||||
props: {user: null},
|
||||
props: {user: null, destination},
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
export default function Login() {
|
||||
export default function Login({ destination }: { destination: string }) {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [rememberPassword, setRememberPassword] = useState(false);
|
||||
@@ -38,13 +39,13 @@ export default function Login() {
|
||||
const router = useRouter();
|
||||
|
||||
const {user, mutateUser} = useUser({
|
||||
redirectTo: "/",
|
||||
redirectTo: destination,
|
||||
redirectIfFound: true,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (user) router.push("/");
|
||||
}, [router, user]);
|
||||
if (user) router.push(destination);
|
||||
}, [router, user, destination]);
|
||||
|
||||
const forgotPassword = () => {
|
||||
if (!email || email.length < 0 || !EMAIL_REGEX.test(email)) {
|
||||
|
||||
Reference in New Issue
Block a user