🛠 iron-session examples: App router
|

+ 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:

GitHub Logo Get the code for this example
How it works
  1. During login, the form is submitted with SWR's useSWRMutation. This makes a POST /session request using fetch.
  2. During logout, the form is submitted with SWR's useSWRMutation. This makes a DELETE /session request using fetch.
  3. 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.

← All examples