Skip to content

Commit 11b8f61

Browse files
committed
fix: remove function jwt token
1 parent 6478754 commit 11b8f61

File tree

1 file changed

+1
-54
lines changed

1 file changed

+1
-54
lines changed

src/helpers/Common.ts

+1-54
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
/* eslint-disable no-unused-vars */
22
import fs from 'fs'
3-
import jwt, {
4-
TokenExpiredError,
5-
JsonWebTokenError,
6-
NotBeforeError,
7-
} from 'jsonwebtoken'
83
import db from 'models/_instance'
94
import { FilterAttributes } from 'models'
105

11-
require('dotenv').config()
12-
13-
const { JWT_SECRET }: any = process.env
146
const { Sequelize } = db
157
const { Op } = Sequelize
168
const invalidValues = [null, undefined, '', false, 0]
@@ -47,44 +39,6 @@ function filterQueryObject(filtered: FilterAttributes[]) {
4739
return resultObject
4840
}
4941

50-
// Get Token from headers
51-
function getToken(headers: any) {
52-
if (headers && headers.authorization) {
53-
const parted = headers.authorization.split(' ')
54-
if (parted.length === 2) {
55-
return parted[1]
56-
}
57-
return null
58-
}
59-
return null
60-
}
61-
62-
// Verify Token
63-
function verifyToken(header: any) {
64-
const token = getToken(header)
65-
66-
try {
67-
if (!token) {
68-
return { data: null, message: 'Token not found!' }
69-
}
70-
71-
const data = jwt.verify(token, JWT_SECRET)
72-
return { data, message: 'Token is verify' }
73-
} catch (err) {
74-
if (err instanceof TokenExpiredError) {
75-
return { data: null, message: `Token ${err.message}` }
76-
}
77-
78-
if (err instanceof JsonWebTokenError) {
79-
return { data: null, message: `Token ${err.message}` }
80-
}
81-
82-
if (err instanceof NotBeforeError) {
83-
return { data: null, message: `Token ${err.message}` }
84-
}
85-
}
86-
}
87-
8842
// Read HTML File
8943
function readHTMLFile(path: any, callback: any) {
9044
fs.readFile(path, { encoding: 'utf-8' }, function (err, html) {
@@ -96,11 +50,4 @@ function readHTMLFile(path: any, callback: any) {
9650
})
9751
}
9852

99-
export {
100-
getUniqueCodev2,
101-
getToken,
102-
verifyToken,
103-
readHTMLFile,
104-
filterQueryObject,
105-
invalidValues,
106-
}
53+
export { getUniqueCodev2, readHTMLFile, filterQueryObject, invalidValues }

0 commit comments

Comments
 (0)