-
Notifications
You must be signed in to change notification settings - Fork 0
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 #173 from jihwooon/issue-99
좋아요 기능 개선
- Loading branch information
Showing
8 changed files
with
47 additions
and
20 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
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,31 @@ | ||
import dotenv from 'dotenv'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import jwt, { type Secret } from 'jsonwebtoken'; | ||
import HttpException from 'src/utils/httpException'; | ||
|
||
dotenv.config(); | ||
|
||
export const generateToken = (loginUser: { userId: number; email: string; password: string }) => { | ||
const payload = { | ||
userId: loginUser.userId, | ||
email: loginUser.email, | ||
}; | ||
|
||
return jwt.sign(payload, process.env.JWT_SECRET as Secret, { | ||
expiresIn: '5m', | ||
}); | ||
}; | ||
|
||
export const validateToken = (token: string) => { | ||
if (token == null || token === undefined || token === '') { | ||
throw new HttpException(`token는 ${token}이 될 수 없습니다`, StatusCodes.BAD_REQUEST); | ||
} | ||
|
||
try { | ||
const decodedJwt = jwt.verify(token, process.env.JWT_SECRET as Secret) as jwt.JwtPayload; | ||
|
||
return decodedJwt; | ||
} catch (e) { | ||
throw new HttpException('인증 할 수 없는 token 입니다', StatusCodes.UNAUTHORIZED); | ||
} | ||
}; |
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