Angular 2/5 JWT 认证示例项目教程

Angular 2/5 JWT 认证示例项目教程

angular2-jwt-authentication-exampleAngular 2/5 JWT Authentication Example项目地址:https://gitcode.com/gh_mirrors/an/angular2-jwt-authentication-example

1. 项目的目录结构及介绍

angular2-jwt-authentication-example/
├── app/
│   ├── app.component.css
│   ├── app.component.html
│   ├── app.component.ts
│   ├── app.module.ts
│   ├── auth.guard.ts
│   ├── auth.interceptor.ts
│   ├── login.component.ts
│   ├── register.component.ts
│   ├── user.service.ts
│   └── users.component.ts
├── index.html
├── package.json
├── systemjs.config.js
├── tsconfig.json
└── README.md

目录结构介绍

  • app/: 包含所有Angular组件、服务和模块。
    • app.component.*: 主组件的样式、模板和逻辑。
    • app.module.ts: 应用的根模块。
    • auth.guard.ts: 认证守卫,用于保护路由。
    • auth.interceptor.ts: HTTP拦截器,用于在每个请求中添加JWT。
    • login.component.ts: 登录组件。
    • register.component.ts: 注册组件。
    • user.service.ts: 用户服务,处理用户数据和认证逻辑。
    • users.component.ts: 用户列表组件。
  • index.html: 应用的入口HTML文件。
  • package.json: 项目依赖和脚本配置。
  • systemjs.config.js: SystemJS配置文件,用于模块加载。
  • tsconfig.json: TypeScript编译配置。
  • README.md: 项目说明文档。

2. 项目的启动文件介绍

index.html

<!DOCTYPE html>
<html>
<head>
    <base href="/">
    <title>Angular 2/5 JWT Authentication Example</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="app.css">
</head>
<body>
    <app-root></app-root>
    <script src="systemjs.config.js"></script>
    <script>
        System.import('app').catch(function(err){ console.error(err); });
    </script>
</body>
</html>

启动文件介绍

  • index.html: 应用的入口文件,包含应用的根组件<app-root>和SystemJS配置。
  • System.import('app'): 使用SystemJS加载应用的根模块。

3. 项目的配置文件介绍

package.json

{
  "name": "angular2-jwt-authentication-example",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "tsc": "tsc",
    "tsc:w": "tsc -w"
  },
  "dependencies": {
    "@angular/common": "~2.4.0",
    "@angular/compiler": "~2.4.0",
    "@angular/core": "~2.4.0",
    "@angular/forms": "~2.4.0",
    "@angular/http": "~2.4.0",
    "@angular/platform-browser": "~2.4.0",
    "@angular/platform-browser-dynamic": "~2.4.0",
    "@angular/router": "~3.4.0",
    "core-js": "^2.4.1",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "zone.js": "^0.7.4"
  },
  "devDependencies": {
    "@types/node": "^6.0.46",
    "concurrently": "^3.1.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.10"
  }
}

angular2-jwt-authentication-exampleAngular 2/5 JWT Authentication Example项目地址:https://gitcode.com/gh_mirrors/an/angular2-jwt-authentication-example

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

田轲浩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值