Hello I am working on a web app created using create-react-app. I am using flask as backend. in flask I am using CORS and cross_origin. My app is as follows
import random
from flask import Flask, request, session, jsonify, Response
from dbconnect import POD_Admin_DB as dbAdmin
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app)
otp = "000000"
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
@app.route('/api/requestOTP',methods=["POST", "OPTIONS"])
@cross_origin(supports_credentials=True)
def pod_requestOTP():
print('requestOTP')
session['otp']=generate_code()
print((session))
print (session['otp'])
#userPhone=request.json['userPhone']
return session['otp']
@app.route('/api/verifyOTP',methods=["POST","OPTIONS"])
@cross_origin(supports_credentials=True)
def pod_verifyOTP():
if request.method =="OPTIONS":
print("here")
return Response(headers={"Content-Type": "application/json charset=utf-8",
"Allow": "POST, OPTIONS",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Methods": "DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT"
})
elif request.method == "POST":
print("verifyOTP")
print((session))
#print(dir(request))
print(request.data)
otp = request.json['pod_Otp']
print((otp))
userPhone=request.json['userPhone']
print(userPhone)
if otp == session['otp']:
print("otp matched")
dbAdmin.connectToDb()
dbAdmin.isClientAlreadyRegistered(userPhone)
return jsonify({"ok":"success"})
else:
print("otp not matching")
return jsonify({"Notok":"success"})
#some method that generates my otp
#def otp_generationMethod():
###code
this is my flask code. I access these both routes from my react app. Everytime when I fetch the pod_verifyOTP() method after requestOTP() from my session from flask becomes empty. I searched many references for this problem but could not fix this. How should I maintain this session?