MCPcopy Create free account
hub / github.com/alpha2phi/python-apps / getUserId

Function getUserId

hackernews/backend-nodejs/src/utils.js:8–25  ·  view source on GitHub ↗
(req, authToken)

Source from the content-addressed store, hash-verified

6}
7
8function 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
27module.exports = {
28 APP_SECRET,

Callers 1

index.jsFile · 0.85

Calls 1

getTokenPayloadFunction · 0.85

Tested by

no test coverage detected