summary refs log tree commit diff
path: root/src/util/checkToken.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-05 22:01:01 +0100
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-05 22:01:01 +0100
commitea41892fef208b10c1bb322de7683c39ebab3dd5 (patch)
treef26559c73196591ac0338a21908a25c806276a7a /src/util/checkToken.ts
parentMove Models/Schemas to server-util (diff)
downloadserver-ea41892fef208b10c1bb322de7683c39ebab3dd5.tar.xz
:wrench: build
Diffstat (limited to 'src/util/checkToken.ts')
-rw-r--r--src/util/checkToken.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/util/checkToken.ts b/src/util/checkToken.ts
new file mode 100644

index 00000000..96c7806a --- /dev/null +++ b/src/util/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); + }); + }); +}