Managing visitor sessions
In Chapter 8, Session Management, we used Remix’s session cookie helpers to implement a login and signup flow. In this section, we will use Remix’s cookie helper to persist additional session data.
You might remember from Chapter 8, Session Management, that cookies are added on the server to an HTTP response using the Set-Cookie header. Once received, the browser attaches the cookie to all subsequent HTTP requests using the Cookie header.
In Remix, we can access incoming HTTP requests in our loader
and action
functions. In our loaders and actions, we can use Remix’s cookie helper functions to parse the cookie data from the request headers and use it to improve the user experience.
In BeeRich, we already utilize a cookie to handle the authentication of our users. However, there are plenty of other use cases for cookies.
Consider the following advanced use case: we aim to offer visitors a taste of our app’s functionality...