Skip to content

Conversation

Raghuboi
Copy link
Contributor

@Raghuboi Raghuboi commented Jan 6, 2022

Checks if there exists a session cookie, if yes then passes the user as a prop to our sign in functional component

</Flex>
);
export async function getServerSideProps({ req }) {
if (req.headers.cookie === null) return { props: { user: null } };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want req.cookies instead

>
<Heading>Sign In</Heading>
if (user)
return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we only want one return statement to render a component. We can conditionally render this using the {user && (<content>)} syntax like we used with the response.

);
export async function getServerSideProps({ req }) {
if (req.headers.cookie === null) return { props: { user: null } };
const user = await req.user;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this exists and we have access to it, do we even need to check if a cookie exists? Also I don't think req.user would be an async function, so we wouldn't need to await.

@Raghuboi Raghuboi requested a review from xTrig January 18, 2022 01:58
@xTrig xTrig linked an issue Jan 27, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a React Context to maintain user state

2 participants