-
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.
Browse files
Browse the repository at this point in the history
[feat] 중간발표
- Loading branch information
Showing
18 changed files
with
879 additions
and
126 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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,36 @@ | ||
import axios from 'axios'; | ||
import { exceptionMessage } from '../module/constant'; | ||
import { SocialUser } from '../interface/SocialUser'; | ||
|
||
const googleAuth = async (googleAccessToken: string) => { | ||
try { | ||
//*사용자 정보 받기 | ||
|
||
const user = await axios({ | ||
method: 'get', | ||
url: `https://www.googleapis.com/oauth2/v2/userinfo?access_token=${googleAccessToken}`, | ||
headers: { | ||
authorization: `Bearer ${googleAccessToken}`, | ||
}, | ||
}); | ||
const userId = user.data.id; | ||
if (!userId) return exceptionMessage.INVALID_USER; | ||
const name = user.data.name; | ||
const email = user.data.email; | ||
|
||
const googleUser: SocialUser = { | ||
userId: userId, | ||
name: name, | ||
email: email, | ||
}; | ||
|
||
return googleUser; | ||
} catch (error) { | ||
console.log('googleAuth error', error); | ||
return null; | ||
} | ||
}; | ||
|
||
export default { | ||
googleAuth, | ||
}; |
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,61 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { exceptionMessage, message, statusCode } from '../module/constant'; | ||
import jwt from '../module/jwtHandler'; | ||
import { success, fail } from '../module/constant/utils'; | ||
|
||
/** | ||
* [GET] accessToken 재발급 | ||
*/ | ||
const getValidAccessToken = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
const accessToken = req.headers.accesstoken; | ||
|
||
//* 토큰이 없다면 | ||
if (!accessToken) | ||
return res | ||
.status(statusCode.BAD_REQUEST) | ||
.send(fail(statusCode.BAD_REQUEST, message.EMPTY_TOKEN)); | ||
|
||
try { | ||
const access = jwt.verify(accessToken as string); | ||
|
||
// 유효하지 않은 accessToken | ||
if (access == exceptionMessage.TOKEN_INVALID) { | ||
return res | ||
.status(statusCode.UNAUTHORIZED) | ||
.send(fail(statusCode.UNAUTHORIZED, message.INVALID_TOKEN)); | ||
} | ||
|
||
// 만료된 accessToken | ||
if (access == exceptionMessage.TOKEN_EXPIRED) { | ||
const data = { | ||
isValid: false, | ||
}; | ||
|
||
return res | ||
.status(statusCode.OK) | ||
.send( | ||
success(statusCode.OK, message.READ_VALID_ACCESS_TOKEN_SUCCESS, data), | ||
); | ||
} | ||
|
||
const data = { | ||
isValid: true, | ||
}; | ||
|
||
return res | ||
.status(statusCode.OK) | ||
.send( | ||
success(statusCode.OK, message.READ_VALID_ACCESS_TOKEN_SUCCESS, data), | ||
); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export default { | ||
getValidAccessToken, | ||
}; |
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,5 @@ | ||
export interface SocialUser { | ||
userId: string; | ||
name: string; | ||
email: string; | ||
} |
Oops, something went wrong.