Code Monkey home page Code Monkey logo

Comments (12)

JakeWoki avatar JakeWoki commented on June 10, 2024

image
WebStorm这个怎么进行调试?设置了断点,但是不可以

from egg-cnode.

JakeWoki avatar JakeWoki commented on June 10, 2024

还有app.js
ctx.cookies.set(app.config.auth_cookie_name, auth_token, opts); // cookie 有效期30天

这个是设置到客户浏览器还是服务端的?

from egg-cnode.

atian25 avatar atian25 commented on June 10, 2024

cookie 肯定是客户端啊。

from egg-cnode.

JakeWoki avatar JakeWoki commented on June 10, 2024

@atian25 那怎么调试的?我用vscode可以调试,用WebStorm调试不了,浏览器也不行

from egg-cnode.

atian25 avatar atian25 commented on June 10, 2024

跟普通的 Node 没啥区别的,如果你 vscode 能调试成功了,说明端口已经正确成功了。

devtool 只需要找对应的 port 来 attach 即可,这块可以看下对应的 Node 调试文章。

WebStorm 默认在 egg-bin 有兼容了它的环境变量,但似乎有些旧版本的 WebStorm 会有问题,不确定。

from egg-cnode.

JakeWoki avatar JakeWoki commented on June 10, 2024

@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.

atian25 avatar atian25 commented on June 10, 2024

你需要了解下 passport.js 以及 egg-passport / egg-passport-github 相关

from egg-cnode.

JakeWoki avatar JakeWoki commented on June 10, 2024

@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.

atian25 avatar atian25 commented on June 10, 2024

不确定,cnode 这块我没参与,这块有可能是用的不好。

from egg-cnode.

JakeWoki avatar JakeWoki commented on June 10, 2024

再请教个问题:
web.js
const userRequired = middleware.userRequired();
这个获取的是什么?好像没看到其它地方配置

from egg-cnode.

atian25 avatar atian25 commented on June 10, 2024

再请教个问题:
web.js
const userRequired = middleware.userRequired();
这个获取的是什么?好像没看到其它地方配置
@JacksonTian @thonatos

https://eggjs.app/zh-cn/basics/middleware.html#router-%E4%B8%AD%E4%BD%BF%E7%94%A8%E4%B8%AD%E9%97%B4%E4%BB%B6

from egg-cnode.

JakeWoki avatar JakeWoki commented on June 10, 2024

之前看了不是太懂这里,刚刚断点了下明白了,谢谢!

from egg-cnode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.