async function getAuthSession(ctx) {
return ctx.req.session.get("user");
}
// pages/protected/protected-route.js
const ProtectedSSRoute = ({ authenticated, user }) => {
if (!authenticated) {
return (
You are not authenticated :(
);
}
return (
You are authenticated as: {user} :)
);
};
export function getServerSideProps(ctx) {
const authSession = getAuthSession(ctx);
if (!authSession) {
return {
props: {
authenticated: false,
},
};
}
return {
props: {
authenticated: true,
user: authSession.user,
},
};
}
export default ProtectedSSRoute;