From 9b3209efd5d421bdb7ede4780b66162ecff41fbd Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Fri, 5 Feb 2021 15:19:24 +0100 Subject: [PATCH] checkToken --- src/checkToken.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/checkToken.ts diff --git a/src/checkToken.ts b/src/checkToken.ts new file mode 100644 index 00000000..96c7806a --- /dev/null +++ b/src/checkToken.ts @@ -0,0 +1,13 @@ +import { JWTOptions } from "./Constants"; +import jwt from "jsonwebtoken"; +import Config from "./Config"; + +export function checkToken(token: string) { + return new Promise((res, rej) => { + jwt.verify(token, Config.getAll().api.security.jwtSecret, JWTOptions, (err, decoded: any) => { + if (err || !decoded) return rej("Invalid Token"); + + return res(decoded); + }); + }); +}