简体   繁体   English

current_user 是 object 是匿名的,即使我已登录

[英]current_user is object is anonymous even though I am logged in

I have built a web-based app using angular and material for which we are using flask as backend.我使用 angular 和我们使用 flask 作为后端的材料构建了一个基于 Web 的应用程序。

Now I am using the flask-login module for managing the users现在我正在使用烧瓶登录模块来管理用户

Now my problem is when I authenticate and do login_user, I can print that user info using current_user.username in /login/ route现在我的问题是当我进行身份验证并执行 login_user 时,我可以使用 /login/ 路由中的 current_user.username 打印该用户信息

Now for some reason, I want to access current_user in other routes in the flask app, but when I tried to do so I get an error that anonymous user has no object called username现在由于某种原因,我想在 flask 应用程序的其他路由中访问 current_user,但是当我尝试这样做时,我收到一个错误,即匿名用户没有 object 称为用户名

I am using mongoalchemy with my flask app.我在 flask 应用程序中使用 mongoalchemy。 Below is the user class code I am using for this.下面是我为此使用的用户 class 代码。

在此处输入图像描述

I solved the issue using jwt, as we are using angular as frontend, flask was not able to store the session for each user I solved the issue using jwt, as we are using angular as frontend, flask was not able to store the session for each user

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM