Refresh Logic

Learn to implement the refresh logic feature for seamless user experience.

The login feature is ready and working well. However, right now the access token expires in 5 minutes. Basically, to get a new access token, the user will have to log in again. Let’s see how we can use the refresh token to request a new access token without logging in again.

The command djangorestframework-simplejwt provides a refresh logic feature. As observed, we’ve been generating refresh tokens and returning them as responses every time registration or login is completed. We’ll just inherit the class from TokenRefreshView and transform it into a viewset.

Adding the viewset

In auth/viewsets, add a new file called refresh.py:

Get hands-on with 1200+ tech skills courses.