-
Notifications
You must be signed in to change notification settings - Fork 5
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 #20 from UMC-FITple/feat/#17_backend_refreshToken
토큰 재발급 완료
- Loading branch information
Showing
11 changed files
with
164 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
import { response } from "../../config/response.js"; | ||
import { status } from "../../config/response.status.js"; | ||
import { refreshTokenService } from "./refreshToken.service.js"; | ||
|
||
export async function refreshTokenLogic(req, res) { | ||
try { | ||
const token = req.cookies.refreshToken; | ||
if (!token) { | ||
return res.send(response(status.REFRESH_TOKEN_NOT_PROVIDED)); | ||
} | ||
const result = await refreshTokenService(token); | ||
|
||
if (!result.success) { | ||
return res.send(response(status.REFRESH_TOKEN_INVALID)); | ||
} | ||
|
||
res.cookie('accessToken', result.accessToken, { httpOnly: true, secure: false }); | ||
res.cookie('refreshToken', result.refreshToken, { httpOnly: true, secure: false }); | ||
|
||
return res.send(response(status.SUCCESS)); | ||
} catch (err) { | ||
console.error(err); | ||
return res.send(response(status.INTERNAL_SERVER_ERROR)); | ||
} | ||
} |
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 async function refreshTokenService(token) { | ||
try { | ||
const decoded = jwt.verify(token,process.env.JWT_SECRET_KEY); | ||
|
||
const accessToken = jwt.sign({ | ||
uuid: decoded.uuid, | ||
}, process.env.JWT_SECRET_KEY, { | ||
expiresIn: '5m' | ||
}); | ||
|
||
const refreshToken = jwt.sign({ | ||
uuid: decoded.uuid, | ||
}, process.env.JWT_SECRET_KEY, { | ||
expiresIn: '1h' | ||
}); | ||
|
||
return { success: true, accessToken, refreshToken }; | ||
} catch (err) { | ||
console.error(err); | ||
return { success: false, message: '토큰 인증 오류' }; | ||
} | ||
} |
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,6 @@ | ||
import express from 'express'; | ||
import { refreshTokenLogic } from '../domains/refreshToken/refreshToken.controller.js'; | ||
|
||
export const refreshTokenRouter = express.Router(); | ||
|
||
refreshTokenRouter.get('/',refreshTokenLogic); |
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,77 @@ | ||
paths: | ||
/FITple/refreshToken: | ||
get: | ||
tags: | ||
- RefreshToken | ||
summary: 토큰 재발급 | ||
responses: | ||
'200': | ||
description: 토큰 재발급 성공! | ||
schema: | ||
type: object | ||
properties: | ||
isSuccess: | ||
type: boolean | ||
example: true | ||
code: | ||
type: number | ||
example: 200 | ||
message: | ||
type: string | ||
example: "success!" | ||
'400': | ||
description: 잘못된 요청 | ||
schema: | ||
type: object | ||
properties: | ||
isSuccess: | ||
type: boolean | ||
example: false | ||
code: | ||
type: string | ||
example: COMMON001 | ||
message: | ||
type: string | ||
example: 잘못된 요청입니다 | ||
'401': | ||
description: refresh 토큰이 존재하지 않음 | ||
schema: | ||
type: object | ||
properties: | ||
isSuccess: | ||
type: boolean | ||
example: false | ||
code: | ||
type: string | ||
example: REFRESHTOKEN001 | ||
message: | ||
type: string | ||
example: refresh 토큰이 존재하지 않았습니다. | ||
'402': | ||
description: 유효하지 않는 refresh 토큰 | ||
schema: | ||
type: object | ||
properties: | ||
isSuccess: | ||
type: boolean | ||
example: false | ||
code: | ||
type: string | ||
example: REFRESHTOKEN002 | ||
message: | ||
type: string | ||
example: 유효하지 않은 refresh 토큰입니다. | ||
'500': | ||
description: 서버 에러 | ||
schema: | ||
type: object | ||
properties: | ||
isSuccess: | ||
type: boolean | ||
example: false | ||
code: | ||
type: string | ||
example: COMMON000 | ||
message: | ||
type: string | ||
example: 서버 에러, 관리자에게 문의 바랍니다. |
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