CSRF issue when using session based authentication for json APIs

Before the token expires, a request is made to an endpoint that is responsible for generating another access token. The server does have access to the refresh token, so once it receives the request, it verifies the refresh token stored in the cookies, and if everything is fine, it returns a new access token to the client, and now the client uses that.

This is a simple way to accomplish it, there are other more advanced and secure measures such as using a fingerprint. This guide is very comprehensive, although it is somewhat focused on GraphQL, it explains all the concepts very well: Your GraphQL guide to handling JWTs on frontend clients