You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
781 B
39 lines
781 B
async function getAuthSession(ctx) {
|
|
return ctx.req.session.get("user");
|
|
}
|
|
|
|
// pages/protected/protected-route.js
|
|
const ProtectedSSRoute = ({ authenticated, user }) => {
|
|
if (!authenticated) {
|
|
return (
|
|
<div>
|
|
<span>You are not authenticated :(</span>
|
|
</div>
|
|
);
|
|
}
|
|
return (
|
|
<div>
|
|
<span>You are authenticated as: {user} :)</span>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export function getServerSideProps(ctx) {
|
|
const authSession = getAuthSession(ctx);
|
|
if (!authSession) {
|
|
return {
|
|
props: {
|
|
authenticated: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
return {
|
|
props: {
|
|
authenticated: true,
|
|
user: authSession.user,
|
|
},
|
|
};
|
|
}
|
|
|
|
export default ProtectedSSRoute; |