Implemented a simple authentication scheme with Firebase and Iron Session
This commit is contained in:
@@ -11,9 +11,31 @@ import ProfileCard from "@/components/ProfileCard";
|
||||
|
||||
// TODO: Remove this import
|
||||
import JSON_RESULTS from "@/demo/user_results.json";
|
||||
import JSON_USER from "@/demo/user.json";
|
||||
|
||||
export default function Home() {
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {User} from "@/interfaces/user";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
const user = req.session.user;
|
||||
|
||||
if (!user) {
|
||||
res.setHeader("location", "/login");
|
||||
res.statusCode = 302;
|
||||
res.end();
|
||||
return {
|
||||
props: {
|
||||
user: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {user: req.session.user},
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
export default function Home({user}: {user: User}) {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
@@ -26,7 +48,7 @@ export default function Home() {
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<main className="w-full h-screen flex flex-col items-center bg-neutral-100">
|
||||
<Navbar profilePicture={JSON_USER.profilePicture} />
|
||||
<Navbar profilePicture={user.profilePicture} />
|
||||
<div className="w-full h-full p-4 relative">
|
||||
<Link href="/exam">
|
||||
<button className={clsx("btn gap-2 top-12 right-12 absolute", infoButtonStyle)}>
|
||||
@@ -36,7 +58,7 @@ export default function Home() {
|
||||
</Link>
|
||||
<section className="h-full w-full flex items-center p-8 gap-12 justify-center">
|
||||
<section className="w-1/2 h-full flex items-center">
|
||||
<ProfileCard user={JSON_USER} className="text-black self-start" />
|
||||
<ProfileCard user={user} className="text-black self-start" />
|
||||
</section>
|
||||
<section className="w-1/2 h-full flex items-center justify-center">
|
||||
<UserResultChart results={JSON_RESULTS} resultKey="total" label="Total exams" className="w-2/3" />
|
||||
|
||||
Reference in New Issue
Block a user