How to make a user loged in (authenticated) in django with Reactjs? i'm using Django rest api to connect django and react

Viewed 417

Here is the view i created in Django Views to verify the if the user is authenticated or not, but even if the user is valide, whene i try to get the currect user i get Null

class LoginView(APIView):
    def get(self,request):
        data = request.data
        usr = authenticate(username=data["username"], password=data["password"])

        if usr in not None:
            login(request,usr)
            return Response(status=status.HTTP_200_OK)
        else:
            return Response(status = status.HTTP_404_NOT_FOUND)

1 Answers

Use one of the authentication methods provided in DRF documentation.

TokenAuthentication is the easiest one to implement, but I recommend you to read the whole section first so you understand the advantages and disadvantages of each method.

Related