This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Router, Response, Request, NextFunction } from "express"; | |
| import express from "express"; | |
| import bodyParser from "body-parser"; | |
| import { validate, Matches, IsDefined } from "class-validator"; | |
| import { plainToClass, Expose } from "class-transformer"; | |
| class UserDto { | |
| @IsDefined() | |
| @Expose() | |
| username: String; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Router, Response, Request } from "express"; | |
| import express from "express"; | |
| import bodyParser from "body-parser"; | |
| import { validate, Matches, IsDefined } from "class-validator"; | |
| import { plainToClass, Expose } from "class-transformer"; | |
| class UserDto { | |
| @IsDefined() | |
| @Expose() | |
| username: String; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Router, Response, Request } from "express"; | |
| import express from "express"; | |
| import bodyParser from "body-parser"; | |
| import { validate, Matches, IsDefined } from "class-validator"; | |
| import { plainToClass, Expose } from "class-transformer"; | |
| class UserDto { | |
| @IsDefined() | |
| @Expose() | |
| username: String; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Router, Response, Request } from "express"; | |
| import express from "express"; | |
| import bodyParser from "body-parser"; | |
| class UserDto { | |
| username: String; | |
| password: String; | |
| email: String; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const random = (length: number): string => { | |
| let result = ""; | |
| const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
| const charactersLength = characters.length; | |
| for (let i = 0; i < length; i++) { | |
| result += characters.charAt(Math.floor(Math.random() * charactersLength)); | |
| } | |
| return result; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| jwtSecret: "ThisIsMySecret", | |
| jwtExpirationSeconds: 300 | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Router } from "express"; | |
| import auth from "./auth"; | |
| import user from "./user"; | |
| const routes = Router(); | |
| routes.use("/auth", auth); | |
| routes.use("/user", user); | |
| export default routes; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Router } from "express"; | |
| import { checkAuthToken } from "../middlewares/checkAuthToken"; | |
| import UserController from "../controllers/UserController" | |
| const router = Router(); | |
| router.get("/check", [ checkAuthToken ], UserController.check); | |
| export default router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Router } from "express"; | |
| import AuthController from "../controllers/AuthController"; | |
| const router = Router(); | |
| router.post("/refreshToken", AuthController.refreshToken); | |
| router.post("/login", AuthController.login); | |
| export default router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Request, Response, NextFunction } from "express"; | |
| import * as jwt from "jsonwebtoken"; | |
| import config from "../config"; | |
| export const checkAuthToken = function(req: Request, res: Response, next: NextFunction) { | |
| const token = <string>req.headers.authorization; | |
| let jwtPayload; | |
| try { | |
| // check if access token is valid | |
| jwtPayload = <any>jwt.verify(token, config.jwtSecret); |
NewerOlder