I've setup a basic authentication, but upon login function which doesnt give any error, if I return something then I get an error stating -
{'session_key': ['Session with this Session key already exists.']}
This is the code:
def header_auth(request):
auth_header = request.META['HTTP_AUTHORIZATION']
encoded_credentials = auth_header.split(' ')[1] # Removes "Basic " to isolate credentials
decoded_credentials = base64.b64decode(encoded_credentials).decode("utf-8").split(':')
return decoded_credentials[0], decoded_credentials[1]
def login_view(request):
username, password = header_auth(request)
user = authenticate(request, username=username, password=password)
if user is not None:
try:
login(request, user)
print('after login')
except Exception as e:
print('login error', e)
return HttpResponse('Authorized', status=200)
else:
return HttpResponse('Not Authorized', status=403)
def logout_view(request):
logout(request)
class FyndUser(AbstractUser):
company_id = models.IntegerField(unique=True)
If I sent the user object instead of Response then I receive the error that the user object has not attribute get.