<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mateusz Jarzebski on Medium]]></title>
        <description><![CDATA[Stories by Mateusz Jarzebski on Medium]]></description>
        <link>https://medium.com/@matjarzebski?source=rss-9f9362458b51------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NN6tZ0stKd2FR245g2Cmjw.jpeg</url>
            <title>Stories by Mateusz Jarzebski on Medium</title>
            <link>https://medium.com/@matjarzebski?source=rss-9f9362458b51------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:41:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matjarzebski/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Update session in NextAuth.js — server site]]></title>
            <link>https://medium.com/@matjarzebski/update-session-in-nextauth-js-server-site-858b5ea4ec?source=rss-9f9362458b51------2</link>
            <guid isPermaLink="false">https://medium.com/p/858b5ea4ec</guid>
            <category><![CDATA[sessions]]></category>
            <category><![CDATA[nextauth]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Mateusz Jarzebski]]></dc:creator>
            <pubDate>Mon, 14 Aug 2023 08:11:06 GMT</pubDate>
            <atom:updated>2023-08-14T08:11:06.971Z</atom:updated>
            <content:encoded><![CDATA[<h3>Update session in NextAuth.js — server site</h3><p>Updating the session in NextAuth.js is as simple as calling useSession from next-auth/react package. Additionally, you’ll have to update callbacks to handle update events as described in the official <a href="https://next-auth.js.org/getting-started/client#updating-the-session">documentation</a>.</p><p>In most of the use cases, this solution is perfect. However, there might be a scenario when you’d like to update the session if using a server call, ex. refreshing access token when it’s close to the expiration date.</p><p>Fortunately, NextAuth comes with REST API so we can make use of it. Here is a simple example:</p><pre>import { getCsrfToken } from &#39;next-auth/react&#39;<br>const updateSession = async (newSession: Record&lt;string, any&gt;) =&gt; {<br>  await fetch(`${process.env.NEXT_PUBLIC_HOST_URL}/api/auth/session`, {<br>    method: &#39;POST&#39;,<br>    headers: {<br>      &#39;content-type&#39;: &#39;application/json&#39;,<br>    },<br>    body: JSON.stringify({<br>      csrfToken: await getCsrfToken(),<br>      data: newSession,<br>    }),<br>  })<br>}</pre><p>Instead of importing getCsrfToken you can also call GET /api/auth/crsf</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=858b5ea4ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>