Posts

Showing posts from October, 2024

Authentication and Authorization in django and React project

 ////////////////Login Serializer//////////////////////////////////////// from rest_framework import serializers from django . contrib . auth import authenticate from rest_framework_simplejwt . tokens import RefreshToken class LoginSerializer ( serializers . Serializer ):     username = serializers . CharField ()     password = serializers . CharField ( write_only = True )     def validate ( self , data ):         username = data .get( 'username' )         password = data .get( 'password' )         if username and password :             user = authenticate ( username = username , password = password )             if user is None :                 raise serializers . ValidationError ( "Invalid username or password." )             if not ...