0

我的代码目前由 react 中的前端和烧瓶后端 api 组成。我正在尝试使用烧瓶会话在我的后端建立一个会话,但我做不到,因为烧瓶从不与用户联系,并且所有请求都通过前端。为此,我正在尝试将 cookie 发布到

在前端,我有类似的东西

import Cookies from 'universal-cookie';
class thingy extends React.Component{
     constructor(props) {
          this.backendurl = 'localhost:5000'
          const cookies = new Cookies();
          this.username = this.props.match.params.user


          cookies.set('UserName', ''+JSON.stringify(this.username), { path: 
               '/profile' });


     }
     onclick = ()=>{
      #post something using axios that sends the cookie to the flask backend so it can be processed
}

}
     render(){
          return(
               <button onClick = {this.onclick}>Click Here</button>
          )
     }
}

后端:

app = Flask(__name__)
app.config["SESSION_PERMANENT"] = False
Session(app)
@app.route('/user',methods=['POST'])
def info():
    #do something with the cookie that react posted in order to user flask_session
return user.name

有人知道如何将 cookie 从 react 发送到烧瓶,然后将烧瓶收到的 cookie 输入到烧瓶会话中吗?

4

0 回答 0