CAL-473 Fixes client-side routing for authed pages (#763)

This commit is contained in:
Omar López authored and GitHub committed 2021-09-24 11:16:46 +01:00
1 parent d3d6778c60
commit 420daec147
14 files changed
+62 -53

No files matched your search

+1 -1
View File
@@ -339,6 +339,6 @@ export async function getServerSideProps(context) {
},
});
return {
props: { user, types }, // will be passed to the page component as props
props: { session, user, types },
};
}
+10 -9
View File
@@ -1,24 +1,23 @@
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { GetServerSideProps } from "next";
import { GetServerSidePropsContext } from "next";
import { useEffect, useState } from "react";
import { getSession } from "@lib/auth";
import prisma from "@lib/prisma";
import { inferSSRProps } from "@lib/types/inferSSRProps";
import Loader from "@components/Loader";
import Shell from "@components/Shell";
dayjs.extend(utc);
export default function Troubleshoot({ user }) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default function Troubleshoot({ user }: inferSSRProps<typeof getServerSideProps>) {
const [loading, setLoading] = useState(true);
const [availability, setAvailability] = useState([]);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [selectedDate, setSelectedDate] = useState(dayjs());
const [selectedDate] = useState(dayjs());
function convertMinsToHrsMins(mins) {
function convertMinsToHrsMins(mins: number) {
let h = Math.floor(mins / 60);
let m = mins % 60;
h = h < 10 ? "0" + h : h;
@@ -97,9 +96,9 @@ export default function Troubleshoot({ user }) {
);
}
export const getServerSideProps: GetServerSideProps = async (context) => {
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const session = await getSession(context);
if (!session) {
if (!session?.user?.id) {
return { redirect: { permanent: false, destination: "/auth/login" } };
}
@@ -114,7 +113,9 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
},
});
if (!user) return { redirect: { permanent: false, destination: "/auth/login" } };
return {
props: { user },
props: { session, user },
};
};