I am trying to get patient details by in frontend
This is my backend function in Django (DRF)
@api_view(['GET'])
@permission_classes([IsAuthenticated])
def getPatientProfile(request):
user = request.user
try:
patient = Patient.objects.get(user_id=user)
print(type(patient))
response = PatientSerializer(patient, many=False)
return Response(response.data)
except Exception as e:
print(e)
return Response(e)
This is my test call which is working fine in backend
GET http://127.0.0.1:8000/profiles/getPatientProfile/ HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjYwNTgzMjU2LCJpYXQiOjE2NjA1NzYwNTYsImp0aSI6ImY3ZGU2OGEwNTI2ZTRmNzBiZjU2MDExYzgzMjFhODI1IiwiZW1haWwiOiJhbGlzaGJhaHJpYXouc0BnbWFpbC5jb20ifQ.BLjghVEhSjizpuP9BAJHdjGreKMvl5Y1xOmhsQ2lQLM
Now this is how I am trying to call API in saga.js but I keep gettig Unauthorized error, I think the issue is in the way I am writing the Authorization: Bearer token line, can anyone help how I can fix this and what the issue is
export const getDetailAPIfunction = async token => {
try {
const response = await axios.get(
"http://127.0.0.1:8000/profiles/getPatientProfile/",{
Authorization: 'Bearer ',token,
}
);
console.log("data recieved = " + response.data);
return response.data;
} catch (error) {
console.log("error = " + error);
throw error;
}
};
function* fetchUserDetail({ payload: token }) {
try {
const response = yield call(getDetailAPIfunction, token);
yield put(getProfileDetailSuccess(response));
} catch (error) {
yield put(getProfileDetailFail(error));
}
}