Skip to content

Commit

Permalink
Merge pull request #11 from HeliosLive/rest-fa-11
Browse files Browse the repository at this point in the history
jwt added
  • Loading branch information
HeliosLive authored Feb 6, 2020
2 parents 85ab35a + 38f54a8 commit d0c262a
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"bcrypt": "^3.0.7",
"class-transformer": "^0.2.3",
"class-validator": "^0.11.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.8.9",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
Expand Down
8 changes: 7 additions & 1 deletion src/login/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { UserLoginDto } from 'tools/dtos/user.dto';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { UserService } from 'src/user/user.service';
import environment from 'tools/environment/environment';
import * as jwt from 'jsonwebtoken';

@Injectable()
export class LoginService {
Expand Down Expand Up @@ -33,7 +35,11 @@ export class LoginService {
});

if (checkPwd) {
return await { success: true, value: existUser };
const authJsonWebToken = jwt.sign(
{ user: existUser },
environment.jwtText,
);
return await { success: true, value: authJsonWebToken };
} else {
return await {
success: false,
Expand Down
1 change: 1 addition & 0 deletions tools/environment/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export default {
mongoUrl:
'mongodb+srv://udemy:Udemy_123@nestjs-jcbid.mongodb.net/test?retryWrites=true&w=majority',
hashText: 'myStrongPasswordHashText',
jwtText: '32dhfnct94q',
};

0 comments on commit d0c262a

Please sign in to comment.