# how can we return custom JWT from dj-rest-auth instead of the session key?

**URL:** <https://forum.djangoproject.com/t/how-can-we-return-custom-jwt-from-dj-rest-auth-instead-of-the-session-key/30635>\
**Category:** Getting Started\
**Created:** [April 29, 2024, 3:53am UTC](https://forum.djangoproject.com/t/how-can-we-return-custom-jwt-from-dj-rest-auth-instead-of-the-session-key/30635 "2024-04-29T03:53:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Smruti-Ranjan-Sahu](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/smruti-ranjan-sahu/32/20898_2.png) [@Smruti-Ranjan-Sahu](https://forum.djangoproject.com/u/Smruti-Ranjan-Sahu)\
**Post date:** [April 29, 2024, 3:53am UTC](https://forum.djangoproject.com/t/how-can-we-return-custom-jwt-from-dj-rest-auth-instead-of-the-session-key/30635/1 "2024-04-29T03:53:40Z")

</div>

We are trying to use dj\_rest\_auth to make social authentication, starting with Google auth, work on a site / app using JWT token pair (access & refresh). Our attempted solution is as follows:

Goal: We are modifying the register & login API endpoints provided by dj\_rest\_auth to return our JWT custom token pair (as returned by the api/token endpoint), instead of the session key.

Possible options:

Option 1: Extend dj\_rest\_auth.registration.views.RegisterView with a CustomRegisterView, modifying the perform\_create method to return the JWT token pair.

Option 2: Let dj\_rest\_auth.registration.views.RegisterView return the session key & token be in the cookie, but modify the token in the cookie to add the logic in our custom token serializer to add additional fields. The above approaches will apply to Loginview as well.

Our questions:

Which of the above is better?

Our preference is for approach 1 - more consistent with our maintenance & use of tokens before social auth. Is there any concern with the above option 1 - ie having register & login endpoints return the JWT token pair? Assuming Option 1 - what is the best way to do it? We are trying to extend the RegisterView - but it’s unclear which method to extend to modify the output. We have already extended the rest\_framework\_simplejwt.serializers.TokenObtainPairSerializer class to modify the get\_token method to return additional fields we need in our token - and this is working with the /api/token endpoints. Is there a way to reuse the same Serializer or code?

Thank you.
