Flasks logout_user() not working with React

Viewed 29

I'm using Flask on backend and it works well when i making logout query via PostMan in browser. But the problem i met, when tried to connect it with React, which i'm using on frontend, is it returns Request failed with status code 401 ...

  • handleLogout.jsx
const handleLogout = async () => {
        try {
            let response = await PostService.userLogout()
            setIsAuth(false);
            sessionStorage.removeItem('access_token');
        } catch (e) {
            alert(e)
        }
    }
  • PostService.jsx
static async userLogout() {
        const resp = await axios.get(lochost + "api/logout")
        return resp.data
    }
  • routes.py
@app.route("/api/logout", methods = ["GET"])
@login_required
def logout():
    print(current_user)
    logout_user()
    return jsonify(msg = "Logged out successfully", status = 200)
0 Answers
Related