简体   繁体   English

基于JWT身份验证和角色路由到Express中的多个Angular 7项目

[英]Routing to multiple Angular 7 projects in Express based on JWT authentication and Role

I have created an Angular 7 project which has multiple applications for different roles, like admin, user, editor, etc. each have different components and view. 我创建了一个Angular 7项目,该项目具有针对不同角色(例如管理员,用户,编辑者等)的多个应用程序。每个应用程序都有不同的组件和视图。

A logged in user will land on its user role application, where as any guest user will land on 'website' application which has login and signup page. 登录的用户将登陆其用户角色应用程序,任何访客用户都将登陆具有登录和注册页面的“网站”应用程序。

My problem is to route using express to different angular applications based on user role determined during authentication. 我的问题是根据身份验证期间确定的用户角色,将Express路由到不同的角度应用程序。 This works with one angular application, but doesn't work with multiple angular application 这适用于一个角度应用程序,但不适用于多个角度应用程序

app.get('/', (req, res) => {
  if (user.isAdmin) {
    return res.sendFile(path.join(__dirname, '../../client/dist/admin/index.html'));
  }
  if (user.isUser) {
    return res.sendFile(path.join(__dirname, '../../client/dist/user/index.html'));
  }
  return res.sendFile(path.join(__dirname, '../../client/dist/website/index.html'));
})

Solved it, just had to rename the index.html to different role names such as below, 解决了它,只需要将index.html重命名为以下不同的角色名称,

app.get('/', (req, res) => {
  if (user.isAdmin) {
    return res.sendFile(path.join(__dirname, '../../client/dist/admin/admin.html'));
  }
  if (user.isUser) {
    return res.sendFile(path.join(__dirname, '../../client/dist/user/user.html'));
  }
  return res.sendFile(path.join(__dirname, '../../client/dist/website/website.html'));
})

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

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