File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change
1
+ // eslint-disable-next-line no-unused-vars
2
+ import { Request } from 'express'
1
3
import jwt , {
2
4
TokenExpiredError ,
3
5
JsonWebTokenError ,
4
6
NotBeforeError ,
5
7
} from 'jsonwebtoken'
8
+ import { isEmpty } from 'lodash'
6
9
7
10
require ( 'dotenv' ) . config ( )
8
11
@@ -20,10 +23,22 @@ function getToken(headers: any) {
20
23
return null
21
24
}
22
25
23
- // Verify Token
24
- function verifyToken ( header : any ) {
25
- const token = getToken ( header )
26
+ function currentToken ( req : Request ) {
27
+ const getCookie = req . getCookies ( )
28
+ const getHeaders = req . getHeaders ( )
29
+
30
+ let curToken = ''
31
+ if ( ! isEmpty ( getCookie . token ) ) {
32
+ curToken = getCookie . token
33
+ } else {
34
+ curToken = getToken ( getHeaders )
35
+ }
26
36
37
+ return curToken
38
+ }
39
+
40
+ // Verify Token
41
+ function verifyToken ( token : string ) {
27
42
try {
28
43
if ( ! token ) {
29
44
return { data : null , message : 'Unauthorized!' }
@@ -46,4 +61,4 @@ function verifyToken(header: any) {
46
61
}
47
62
}
48
63
49
- export { getToken , verifyToken }
64
+ export { getToken , currentToken , verifyToken }
You can’t perform that action at this time.
0 commit comments