Skip to content

Commit b6d7768

Browse files
committed
Typescript Bootcamp
1 parent 8030e15 commit b6d7768

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

rest-api/src/routes/login.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {AppDataSource} from "../data-source";
44
import {User} from "../models/user";
55
import {calculatePasswordHash} from "../utils";
66
const JWT_SECRET = process.env.JWT_SECRET;
7+
const jwt = require("jsonwebtoken");
78

89
export async function login(request: Request, response: Response, next:NextFunction) {
910

@@ -47,14 +48,21 @@ export async function login(request: Request, response: Response, next:NextFunct
4748

4849
const {pictureUrl, isAdmin} = user;
4950

51+
const authJwt = {
52+
userId: user.id,
53+
email,
54+
isAdmin
55+
};
5056

57+
const authJwtToken = await jwt.sign(authJwt, JWT_SECRET);
5158

5259
response.status(200).json({
5360
user: {
5461
email,
5562
pictureUrl,
5663
isAdmin
57-
}
64+
},
65+
authJwtToken
5866
});
5967

6068
}

0 commit comments

Comments
 (0)