(req, authToken)
| 6 | } |
| 7 | |
| 8 | function getUserId(req, authToken) { |
| 9 | if (req) { |
| 10 | const authHeader = req.headers.authorization; |
| 11 | if (authHeader) { |
| 12 | const token = authHeader.replace('Bearer ', ''); |
| 13 | if (!token) { |
| 14 | throw new Error('No token found'); |
| 15 | } |
| 16 | const { userId } = getTokenPayload(token); |
| 17 | return userId; |
| 18 | } |
| 19 | } else if (authToken) { |
| 20 | const { userId } = getTokenPayload(authToken); |
| 21 | return userId; |
| 22 | } |
| 23 | |
| 24 | throw new Error('Not authenticated'); |
| 25 | } |
| 26 | |
| 27 | module.exports = { |
| 28 | APP_SECRET, |
no test coverage detected