-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from redacademy/af-bugfix-auth
resolve auth bug
- Loading branch information
Showing
4 changed files
with
17 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
const jwt = require('jsonwebtoken') | ||
const jwt = require("jsonwebtoken"); | ||
|
||
function getUserId(context) { | ||
const Authorization = context.request.get('Authorization') | ||
const Authorization = context.request.get("Authorization"); | ||
if (Authorization) { | ||
const token = Authorization.replace('Bearer ', '') | ||
const { userId } = jwt.verify(token, process.env.APP_SECRET) | ||
return userId | ||
const token = Authorization.replace("Bearer ", ""); | ||
const { userId } = jwt.verify(token, process.env.APP_SECRET); | ||
return userId; | ||
} | ||
|
||
throw new AuthError() | ||
throw new AuthError(); | ||
} | ||
|
||
class AuthError extends Error { | ||
constructor() { | ||
super('Not authorized') | ||
super("Not authorized"); | ||
} | ||
} | ||
|
||
module.exports = { | ||
getUserId, | ||
AuthError | ||
} | ||
}; |