Post any code you think might be relevant (one fenced block per file)
class SignIn(generics.CreateAPIView):
# Override the authentication/permissions classes so this endpoint
# is not authenticated & we don't need any permissions to access it.
authentication_classes = ()
permission_classes = ()
# Serializer classes are required for endpoints that create data
serializer_class = UserSerializer
def post(self, request):
creds = request.data['credentials']
print(creds)
# We can pass our email and password along with the request to the
# `authenticate` method. If we had used the default user, we would need
# to send the `username` instead of `email`.
user = authenticate(request, email=creds['email'], password=creds['password'])
# Is our user is successfully authenticated...
if user is not None:
# And they're active...
if user.is_active:
# Log them in!
login(request, user)
# Finally, return a response with the user's token
return Response({
'user': {
'id': user.id,
'email': user.email,
'token': user.get_auth_token()
}
})
else:
return Response({ 'msg': 'The account is inactive.' }, status=status.HTTP_400_BAD_REQUEST)
else:
return Response({ 'msg': 'The username and/or password is incorrect.' }, status=status.HTTP_422_UNPROCESSABLE_ENTITY)
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
MultiValueDictKeyError at /sign-in/
What is your best guess as to the source of the problem?
Originally, I thought that it was related to not having a page to show successful login, but then I looked into the code and it says that it should return the login creds & token or a specific error message, but I am not seeing either one of those..
What things have you already tried to solve the problem?
tested it in Postman and it is working
Googling and stack overflow
found out that the default request body was missing the 'credentials' key.. so I changed the raw data request and it worked:
![Uploading Screen Shot 2022-04-25 at 8.18.28 AM.png…]()
What stack are you using?
(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)
DR
What's the problem you're trying to solve?
/sign-in/ post is not working
Post any code you think might be relevant (one fenced block per file)
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
MultiValueDictKeyError at /sign-in/
What is your best guess as to the source of the problem?
Originally, I thought that it was related to not having a page to show successful login, but then I looked into the code and it says that it should return the login creds & token or a specific error message, but I am not seeing either one of those..
What things have you already tried to solve the problem?
tested it in Postman and it is working Googling and stack overflow
Paste a link to your repository here composting_mgmt_systems-api