Generally speaking, storing a JWT token (especially a refresh token) as a cookie isn't the best thing to do, as it means you're potentially "leaking" the token in every request where that cookie is valid, rather than intentionally sending it as a header only when you intend to (among other issues).
Also, you've basically reinvented something like django.contrib.sessions.backends.signed_cookies, but with extra complexity :)
But, if you really intend to do this, you could solve this as follows:
1) Replace your authentication class with a subclass of rest_framework_simplejwt.authentication.JWTAuthentication (or JWTTokenUserAuthentication)
2) Replace authenticate() with your own version, which generates a new access token if the old one has expired, using the refresh token
Or, in your client code:
1) Catch a 401 (or 403? can't remember which is generated for an expired token)
2) Call your "refresh" view to update the access token
3) Retry the original request that generated the 401/403
But really, it's much simpler (IMO) to keep the JWT tokens in javascript. Your client code can then simply check the expiry of the access token before each request, and call the refresh view to get a replacement before making the request.
I hope that helps!
Kind Regards,
Michael Thomas