+ client components, route handlers, and SWR
How to test: Login and refresh the page to see iron-session in action. Bonus: open multiple tabs to see the state being reflected by SWR automatically.
Loading...
The following pages are protected and will redirect back here if you're not logged in:
How it works
- During login, the form is submitted with SWR's useSWRMutation. This makes a POST /session request using fetch.
- During logout, the form is submitted with SWR's useSWRMutation. This makes a DELETE /session request using fetch.
- In all other places, the content of the session is optimistally rendered using the most recent value, and never gets outdated. This is automatically handled by SWR using mutations and revalidation.