Comments (12)
from egg-cnode.
还有app.js
ctx.cookies.set(app.config.auth_cookie_name, auth_token, opts); // cookie 有效期30天
这个是设置到客户浏览器还是服务端的?
from egg-cnode.
cookie 肯定是客户端啊。
from egg-cnode.
@atian25 那怎么调试的?我用vscode可以调试,用WebStorm调试不了,浏览器也不行
from egg-cnode.
跟普通的 Node 没啥区别的,如果你 vscode 能调试成功了,说明端口已经正确成功了。
devtool 只需要找对应的 port 来 attach 即可,这块可以看下对应的 Node 调试文章。
WebStorm 默认在 egg-bin 有兼容了它的环境变量,但似乎有些旧版本的 WebStorm 会有问题,不确定。
from egg-cnode.
@atian25 再请教个问题
local.js
// 验证用户是否登录
return async function(ctx, next) {
ctx.locals.config = app.config;
ctx.locals.Loader = Loader;
ctx.locals.assets = assets;
ctx.locals.csrf = ctx.csrf;
await next();
};
auth_user.js
// 验证用户是否登录
return async function(ctx, next) {
// Ensure current_user always has defined.
ctx.locals.current_user = null;
// if (ctx.app.config.debug && ctx.cookies.get('mock_user')) {
// const mockUser = JSON.parse(ctx.cookies.get('mock_user'));
// ctx.user = new ctx.model.User(mockUser);
// if (mockUser.is_admin) {
// ctx.user.is_admin = true;
// }
// return await next();
// }
const { user } = ctx;
if (!user) {
return await next();
}
const count = await ctx.service.message.getMessagesCount(user._id);
user.messages_count = count;
ctx.locals.current_user = user;
await next();
};
这里怎么验证用户是否登录的?没看懂
from egg-cnode.
你需要了解下 passport.js 以及 egg-passport / egg-passport-github 相关
from egg-cnode.
@atian25 验证登录不是passport的serializeUser和deserializeUser对sessions持久化有关吗?
return async function(ctx, next) {
// Ensure current_user always has defined.
ctx.locals.current_user = null;
// if (ctx.app.config.debug && ctx.cookies.get('mock_user')) {
// const mockUser = JSON.parse(ctx.cookies.get('mock_user'));
// ctx.user = new ctx.model.User(mockUser);
// if (mockUser.is_admin) {
// ctx.user.is_admin = true;
// }
// return await next();
// }
const { user } = ctx;
if (!user) {
return await next();
}
const count = await ctx.service.message.getMessagesCount(user._id);
user.messages_count = count;
ctx.locals.current_user = user;
await next();
};
这个是设置当前用户,并且获取未读消息数吧
return async function(ctx, next) {
ctx.locals.config = app.config;
ctx.locals.Loader = Loader;
ctx.locals.assets = assets;
ctx.locals.csrf = ctx.csrf;
await next();
};
这个也是设置一些属性,和验证登录没关系啊。注释写错了吧
from egg-cnode.
不确定,cnode 这块我没参与,这块有可能是用的不好。
from egg-cnode.
再请教个问题:
web.js
const userRequired = middleware.userRequired();
这个获取的是什么?好像没看到其它地方配置
from egg-cnode.
再请教个问题:
web.js
const userRequired = middleware.userRequired();
这个获取的是什么?好像没看到其它地方配置
@JacksonTian @thonatos
from egg-cnode.
之前看了不是太懂这里,刚刚断点了下明白了,谢谢!
from egg-cnode.
Related Issues (20)
- docker-compose.yml中mongodb volumes问题
- 配置Alinode报错nodeinstall --install-alinode ^3 HOT 1
- egg-oauth2-server
- cnode 502, rescue ? HOT 2
- ctx.message 不能使用中文,但是你们源码中大量使用,怎么做到的
- [egg:core:ready_timeout] 10 seconds later redis.js was still unable to finish. HOT 2
- 根目录的app.js一启动是调用了吗?怎么用的? HOT 1
- 样例数据
- 没有阿里云怎么部署?
- Bootstrap 升级到3
- egg项目使用egg-sequlize,如何控制应用级别的数据库连接池大小
- 无法登录测试环境
- 求惑,config的数据是如何进入到layout.html模板里面的
- 论坛图床是不是挂了,头像好多看不见
- 论坛无法访问了么? HOT 13
- 运行nodeinstall --install-alinode ^3 报unknow version错误
- bcrypt 的 compare 方法,为什么在 TODO 中建议改成异步的调用方式,同步的调用方式有什么问题么?
- CNode社区的API页面未居中
- 论坛又无法访问了吗 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from egg-cnode.