-
Notifications
You must be signed in to change notification settings - Fork 1
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 #9 from OASIS-YOP/feat/api
Feat/api
- Loading branch information
Showing
6 changed files
with
305 additions
and
174 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import jwt from 'jsonwebtoken'; | ||
|
||
export const verifyToken = (req, res, next) => { | ||
// 인증 완료 | ||
try { | ||
req.decoded = jwt.verify(req.headers.authorization, process.env.JWT_SECRET_KEY); | ||
console.log(req.decoded); | ||
return next(); | ||
} | ||
|
||
// 인증 실패 | ||
catch (error) { | ||
if (error.name === 'TokenExpireError') { | ||
return res.status(419).json({ | ||
code: 419, | ||
message: '토큰이 만료되었습니다.' | ||
}); | ||
} | ||
return res.status(401).json({ | ||
code: 401, | ||
message: '유효하지 않은 토큰입니다.' | ||
}); | ||
} | ||
}; |
Oops, something went wrong.