db = SQLAlchemy()
DB_NAME = "database.db"
app = Flask(__name__)
ma = Marshmallow(app)
jwt = JWTManager()
def create_app():
app.config['SECRET_KEY'] = 'hjshjhdjahkjshkjdhjs'
app.config["JWT_SECRET_KEY"] = "super-secret" # Change this!
#app.config['JWT_ACCESS_COOKIE_PATH'] = 'http://localhost:8080/#/adminpanel'
app.config["JWT_TOKEN_LOCATION"] = ["cookies"]
app.config['JWT_COOKIE_CSRF_PROTECT'] = False
app.config['JWT_COOKIE_SECURE'] = False
#app.config['JWT_COOKIE_DOMAIN'] = 'http://localhost'
#app.config['JWT_COOKIE_SAMESITE'] = 'None'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
UPLOAD_FOLDER = '/home/user/nodejs/emal-new/vue-spa/src/assets/uploaded_images/'
#UPLOAD_FOLDER = '/home/user/flask/Emal_api/Emal/static/uploaded_images/'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
db.init_app(app)
jwt.init_app(app)
migrate = Migrate(app, db)
CORS(app, supports_credentials=True)
@admin_views.route("/api/login/", methods=["POST",'GET'])
@cross_origin()
def login():
if request.method == 'POST':
username = request.form.get("login")
password = request.form.get("password")
print(username,password)
if password == 'password':
access_token = create_access_token(identity=username,expires_delta=datetime.timedelta(minutes=30))
response = jsonify({'headers': {
'Authorization': 'Bearer ' + access_token,
'Set-Cookie': 'access_token_cookie=' + access_token,
}})
#resp = jsonify(access_token=access_token)
#resp = make_response()
#resp.set_cookie('access_token_cookie', access_token,httponly=False, samesite=None, domain="dev.localhost")
set_access_cookies(response, access_token)
return response, 200
else:
return jsonify({"msg": "Bad username or password"}), 401
----------------------------------------------------------------------
axios.post( 'http://localhost:5000/adminpanel/api/login/', formData,{withCredentials: true,}) #also added withCredentials: true to vue js frontend