I properly setup cros. Trying to send cookie to client browser but don’t know where I am doing mistake and cookie not going to client browser:
setting.py
CORS_ALLOWED_ORIGINS = [
"http://*",
"https://*",]
CORS_ORIGIN_WHITELIST = [
"http://*",
"https://*",]
CSRF_TRUSTED_ORIGINS = [
"http://*",
"https://*",
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_CREDENTIALS = True
SESSION_COOKIE_SECURE = True
my api code:
from django.http import HttpResponse,JsonResponse
@api_view(["POST","GET"])
def UserProfileAPI(request):
if request.method == "POST":
#...others code performing validation if success then allow user login
login(request, user)
#refresh = RefreshToken.for_user(user)
#access_token = str(refresh.access_token)
#refresh_token = str(refresh)
serializers = AuthorProfileSerialzers(data=request.data)
try:
existing_profile= AuthorProfile.objects.get(author = request.user)
except:
existing_profile = None
if not existing_profile:
if serializers.is_valid():
instance = serializers.save()
instance.author = request.user
instance.author_pic = request.data.get("profile_image")
instance.save()
response = HttpResponse('Cookie set successfully')
# Set a cookie named 'my_cookie' with a value 'cookie_value'
response.set_cookie('my_cookie', 'cookie_value', max_age=3600, path='/',samesite=None,secure=False)
return response
# return Response({"detail":"sucess","jwt_token":access_token,"refresh_token":refresh_token}, status=status.HTTP_200_OK)
I am receiving the 200 response from backend but don’t know why cookie isn’t sending to browser