Is there any way to change view of Django-rest-auth of login?

Kashyap

I've created rest APIs using Django-rest-auth, in login, it's returning key and some user info, But I need to add some status like success and message and some other things. Is there any way to override view of django-rest-auth for login?

class TokenSerializer(serializers.ModelSerializer):
    user = UserSerializer(many=False, read_only=True)  # this is add by myself.
    device = DeviceSerializer(many=True, read_only=True)

    class Meta:
        model = TokenModel
        fields = ('key', 'user', 'device',)
JPG

Create a custom view class and use it

from rest_auth.views import LoginView


class CustomLoginView(LoginView):
    def get_response(self):
        orginal_response = super().get_response()
        mydata = {"message": "some message", "status": "success"}
        orginal_response.data.update(mydata)
        return orginal_response

and change your urls.py as

urlpatterns = [
                  url(r'custom/login/', CustomLoginView.as_view(), name='my_custom_login')

              ] 

now you should use the endpoint /custom/login/ instead of /rest-auth/login

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Is there any way to get Firebase Auth User UID?

django.contrib.auth.login() function not returning any user as logged in

Django REST Framework and python-social-auth for registration/login user

django rest auth email validation

How to change default Laravel Auth login view

Django REST Framework: require login to view API

django rest auth returns AnonymousUser

Is there any way to change view of Django-rest-auth of register?

django override auth login method

How to use a custom decorator with default Django auth login view

Is there any way to change username field label in user authentication login page?

Is there any way of mentioning two login_redirect_urls in django?

Is there any way to login to Django admin interface using username or email?

View [auth.login] not found

Is there any way to get reversed nested serializers in django rest framework?

How do I create a Login view with django-rest-framework

Cakephp Auth login REST response

Laravel 5 Auth - Change Login Route

is there any way to change the default text editor for textfield django in admin panel?

Any way to change order of photos in stack view?

Django rest auth with Google and VK?

How can I do my logic in `http://127.0.0.1:8000/rest-auth/login/` of `django-rest-auth`?

change the page from Auth to Home after login

Django Rest Framework JWT Auth

failed to configure axios with django rest auth to login and get auth token

Is there any way to make a second LOGIN_REDIRECT_URL in settings.py in Django?

how to create custom login view with Django rest_auth?

Is there a way to login in django rest api in browser without UI?

Login logic in React via Django Rest_auth requires password although submitted in body