|
1 | | -# Angular 8 Spring Boot JWT Authentication example |
2 | | - |
3 | | -> [Angular 8 + Spring Boot: JWT Authentication example](https://bezkoder.com/angular-spring-boot-jwt-auth/) |
4 | | -
|
5 | 1 | # Angular 8 JWT Authentication example |
6 | 2 |
|
7 | 3 | For more detail, please visit: |
8 | 4 | > [Angular 8 JWT Authentication with HttpInterceptor and Router](https://bezkoder.com/angular-jwt-authentication/) |
9 | 5 |
|
10 | | -This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.3.21. |
11 | | - |
12 | | -## Development server |
| 6 | +## With Spring Boot back-end |
13 | 7 |
|
14 | | -Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. |
| 8 | +> [Angular 8 + Spring Boot: JWT Authentication & Authorization example](https://bezkoder.com/angular-spring-boot-jwt-auth/) |
15 | 9 |
|
16 | | -## Code scaffolding |
| 10 | +Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. |
17 | 11 |
|
18 | | -Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. |
| 12 | +## With Node.js Express back-end |
19 | 13 |
|
20 | | -## Build |
| 14 | +> [Node.js Express + Angular 8: JWT Authentication & Authorization example](https://bezkoder.com/node-js-express-angular-jwt-auth/) |
21 | 15 |
|
22 | | -Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. |
| 16 | +Open `app/_helpers/auth.interceptor.js`, modify the code to work with **x-access-token** like this: |
| 17 | +```js |
| 18 | +... |
23 | 19 |
|
24 | | -## Running unit tests |
| 20 | +// const TOKEN_HEADER_KEY = 'Authorization'; // for Spring Boot back-end |
| 21 | +const TOKEN_HEADER_KEY = 'x-access-token'; // for Node.js Express back-end |
25 | 22 |
|
26 | | -Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). |
| 23 | +@Injectable() |
| 24 | +export class AuthInterceptor implements HttpInterceptor { |
| 25 | + ... |
27 | 26 |
|
28 | | -## Running end-to-end tests |
| 27 | + intercept(req: HttpRequest<any>, next: HttpHandler) { |
| 28 | + ... |
| 29 | + if (token != null) { |
| 30 | + // for Spring Boot back-end |
| 31 | + // authReq = req.clone({ headers: req.headers.set(TOKEN_HEADER_KEY, 'Bearer ' + token) }); |
29 | 32 |
|
30 | | -Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). |
| 33 | + // for Node.js Express back-end |
| 34 | + authReq = req.clone({ headers: req.headers.set(TOKEN_HEADER_KEY, token) }); |
| 35 | + } |
| 36 | + return next.handle(authReq); |
| 37 | + } |
| 38 | +} |
31 | 39 |
|
32 | | -## Further help |
| 40 | +... |
| 41 | +``` |
33 | 42 |
|
34 | | -To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). |
| 43 | +Run `ng serve --port 8081` for a dev server. Navigate to `http://localhost:8081/`. |
0 commit comments