-
Notifications
You must be signed in to change notification settings - Fork 9
/
profile-ssr.js
37 lines (32 loc) · 855 Bytes
/
profile-ssr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from "react";
import Layout from "../components/layout";
import { authorize } from "../lib/auth";
const ProfileSSR = ({ user, authorized }) => {
return (
<Layout>
<p className="lead">
{authorized ? (
<>Logged in as {user.username}</>
) : (
<>You need to login</>
)}
</p>
<p>
Use the <code>authorize</code> middleware with{" "}
<code>getServerSideProps</code> to prevent unauthorized users to access
static pages.
</p>
<style jsx>{`
.lead {
font-size: 1.5rem;
font-weight: 300;
}
`}</style>
</Layout>
);
};
export const getServerSideProps = authorize(async ({ req, res }) => {
const { user, authorized } = req;
return { props: { user, authorized } };
});
export default ProfileSSR;