I am trying to create an endpoint for when a user is logged in to check the 
status of user is logged in react js. For my backend, I use django 
rest-framework. Here is the backend code.

serializers.py:

from rest_framework import serializers
 from rest_framework_jwt.settings import api_settings from 
django.contrib.auth.models import User class 
UserSerializer(serializers.ModelSerializer): class Meta: model = User fields = 
('username',) # handle signups only class 
UserSerializerWithToken(serializers.ModelSerializer): token = 
serializers.SerializerMethodField() password = 
serializers.CharField(write_only=True) def get_token(self, obj): 
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER jwt_encode_handler = 
api_settings.JWT_ENCODE_HANDLER payload = jwt_payload_handler(obj) token = 
jwt_encode_handler(payload) return token def create(self, validated_data): 
password = validated_data.pop('password', None) inst = 
self.Meta.model(**validated_data) if password is not None: 
inst.set_password(password) inst.save() return inst class Meta: fields = 
('token', 'username', 'password')

urls.py: The following code is where I would create the endpoint

from django.contrib import adminfrom django.urls import path, includefrom 
django.conf import settingsfrom django.conf.urls.static import staticfrom 
rest_framework_jwt.views import obtain_jwt_tokenfrom rest_framework_jwt.views 
import verify_jwt_token

urlpatterns = [
    path('api-auth/', include('rest_framework.urls')),
    # path('rest-auth/', include('rest_auth.urls')),
    # path('rest-auth/registration/', include('rest_auth.registration.urls')),
    path('token-auth/', obtain_jwt_token),
    path('api-token-verify/', verify_jwt_token),
    path('login/', include('login.urls')),
    path('admin/', admin.site.urls),
    path('api/', include('menus.api.urls')),
    path('phlogapi/', include('phlogfeeder.phlogapi.urls'))]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I am confused on how to create a endpoint with jwt.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/9327e4b4-cfa8-4209-bb2a-435fa74b080a%40googlegroups.com.

Reply via email to