Skip to content

Commit

Permalink
sample(@nestjs) update authentication example (passport)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Apr 29, 2018
1 parent 6630313 commit 484a2eb
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 76 deletions.
1 change: 1 addition & 0 deletions sample/19-auth/package.json
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@nestjs/common": "^5.0.0",
"@nestjs/core": "^5.0.0",
"@nestjs/passport": "^1.0.2",
"passport": "^0.4.0",
"passport-http-bearer": "^1.0.1",
"passport-jwt": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion sample/19-auth/src/auth/auth.controller.ts
@@ -1,6 +1,6 @@
import { Controller, Get, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { AuthService } from './auth.service';
import { AuthGuard } from '../passport/auth.guard';

@Controller('auth')
export class AuthController {
Expand Down
7 changes: 4 additions & 3 deletions sample/19-auth/src/auth/auth.service.ts
Expand Up @@ -5,11 +5,12 @@ import { JwtPayload } from './interfaces/jwt-payload.interface';
@Injectable()
export class AuthService {
async createToken() {
const expiresIn = 3600;
const user: JwtPayload = { email: 'test@email.com' };
const expiresIn = 3600;
const accessToken = jwt.sign(user, 'secretKey', { expiresIn });
return {
expiresIn: expiresIn,
accessToken: jwt.sign(user, 'secretKey', { expiresIn }),
expiresIn,
accessToken,
};
}

Expand Down
2 changes: 1 addition & 1 deletion sample/19-auth/src/auth/jwt.strategy.ts
@@ -1,6 +1,6 @@
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { AuthService } from './auth.service';
import { PassportStrategy } from '../passport/passport.strategy';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtPayload } from './interfaces/jwt-payload.interface';

Expand Down
39 changes: 0 additions & 39 deletions sample/19-auth/src/passport/auth.guard.ts

This file was deleted.

13 changes: 0 additions & 13 deletions sample/19-auth/src/passport/passport.serializer.ts

This file was deleted.

19 changes: 0 additions & 19 deletions sample/19-auth/src/passport/passport.strategy.ts

This file was deleted.

1 change: 1 addition & 0 deletions sample/19-auth/tslint.json
Expand Up @@ -16,6 +16,7 @@
"member-access": [false],
"no-empty-interface": false,
"no-empty": false,
"ban-types": false,
"arrow-parens": false,
"object-literal-sort-keys": false,
"no-unused-expression": false,
Expand Down

0 comments on commit 484a2eb

Please sign in to comment.