Tivix / django-rest-auth

This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)
www.tivix.com
MIT License
2.41k stars 661 forks source link

Customize login view response #552

Open math77 opened 5 years ago

math77 commented 5 years ago

Hello,

how can I customize the response of the login view so that it returns the token and also the id of the logged in user?

ethanyuwang commented 4 years ago

did you figure out a solution? im also looking for a way to return more info about the user

mateoKutnjak commented 4 years ago

Create custom view that inherits LoginView

from rest_auth.registration.views import LoginView

...

class LoginViewCustom(LoginView):
    authentication_classes = (TokenAuthentication,)

    def post(self, request, *args, **kwargs):
        response = super().post(request, *args, **kwargs)

        user_serializer_data = UserSerializer(self.user, context={'request': request})
        aaa = {'user': user_serializer_data.data}
        aaa.update(response.data)

        return Response(aaa)
math77 commented 4 years ago

Ohh, thanks! That works for me.

akash-s-simformsolutions commented 3 years ago

It's working fine. Great work. @mateoKutnjak