Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Server] / #10 / tokenFunction 및 dummy data 구현 #29

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DATABASE_PASSWORD
ACCESS_SECRET
REFRESH_SECRET
23 changes: 23 additions & 0 deletions server/controllers/tokenFunction/accessToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require("dotenv").config();
const { sign, verify } = require("jsonwebtoken");

module.exports = {
generateAccessToken: (data) => {
// TODO: Access token으로 sign합니다.
return sign(data, process.env.ACCESS_SECRET, { expiresIn: "2h" });
},
isAuthorized: (req) => {
// TODO: JWT 토큰 정보를 받아서 검증합니다.
const token = req.headers.Authorization;
if (!token) {
return null;
} else {
try {
const realToken = token.split(" ")[1];
return verify(realToken, process.env.ACCESS_SECRET);
} catch (error) {
return null;
}
}
},
};
29 changes: 29 additions & 0 deletions server/controllers/tokenFunction/refreshToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require("dotenv").config();
const { sign, verify } = require("jsonwebtoken");

module.exports = {
generateRefreshToken: (data) => {
return sign(data, process.env.REFRESH_SECRET, { expiresIn: "30d" });
},
sendRefreshToken: (res, refreshToken) => {
// TODO: JWT 토큰을 쿠키로 전달합니다.
res.cookie("jwt", refreshToken, {
httpOnly: true,
secure: true,
sameSite: "none",
});
},
isAuthorized: (req) => {
// TODO: JWT 토큰 정보를 받아서 검증합니다.
const token = req.cookies;
if (!token) {
return null;
} else {
try {
return verify(token.jwt, process.env.REFRESH_SECRET);
} catch (error) {
return null;
}
}
},
};
44 changes: 40 additions & 4 deletions server/seeders/20210826045551-demo-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,46 @@ module.exports = {
"users",
[
{
username: "John Doe",
email: "[email protected]",
password: "asdf!",
phone: "010010000",
username: "배윤수",
email: "[email protected]",
password: "yunsu12345",
phone: "01012341234",
userPic: "",
createdAt: new Date(),
updatedAt: new Date(),
},
{
username: "김민재",
email: "[email protected]",
password: "minjman2659123",
phone: "01012341234",
userPic: "",
createdAt: new Date(),
updatedAt: new Date(),
},
{
username: "이나은",
email: "[email protected]",
password: "naunendjfiasdf",
phone: "01012341234",
userPic: "",
createdAt: new Date(),
updatedAt: new Date(),
},
{
username: "강영서",
email: "[email protected]",
password: "kangggg123",
phone: "01012341234",
userPic: "",
createdAt: new Date(),
updatedAt: new Date(),
},
{
username: "권지용",
email: "[email protected]",
password: "gdragon8888",
phone: "01088888888",
userPic: "",
createdAt: new Date(),
updatedAt: new Date(),
Expand Down
72 changes: 72 additions & 0 deletions server/seeders/20210826051026-demo-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,78 @@ module.exports = {
createdAt: new Date(),
updatedAt: new Date(),
},
{
wordName: "스불재",
wordMean: "스스로 불러온 재앙",
thumbsup: 0,
userId: 1,
createdAt: new Date(),
updatedAt: new Date(),
},
{
wordName: "자강두천",
wordMean: "자존심 강한 두 천재의 대결",
thumbsup: 0,
userId: 2,
createdAt: new Date(),
updatedAt: new Date(),
},
{
wordName: "갑분싸",
wordMean: "갑자기 분위기 싸해짐",
thumbsup: 0,
userId: 3,
createdAt: new Date(),
updatedAt: new Date(),
},
{
wordName: "자만추",
wordMean: "자장면에 만두 추가",
thumbsup: 5,
userId: 4,
createdAt: new Date(),
updatedAt: new Date(),
},
{
wordName: "자만추",
wordMean: "자신만만 추성훈",
thumbsup: 20,
userId: 5,
createdAt: new Date(),
updatedAt: new Date(),
},
{
wordName: "자만추",
wordMean: "자신만만 추사랑",
thumbsup: 0,
userId: 2,
createdAt: new Date(),
updatedAt: new Date(),
},
{
wordName: "번달번줌",
wordMean: "번호 달라고 하면 번호줌?",
thumbsup: 10,
userId: 5,
createdAt: new Date(),
updatedAt: new Date(),
},
{
wordName: "별다줄",
wordMean: "별걸 다 줄인다",
thumbsup: 7,
userId: 1,
createdAt: new Date(),
updatedAt: new Date(),
},
{
wordName: "애빼시",
wordMean: "애교 빼면 시체",
thumbsup: 2,
userId: 3,
createdAt: new Date(),
updatedAt: new Date(),
},
],
{}
);
Expand Down
36 changes: 36 additions & 0 deletions server/seeders/20210826051319-demo-thumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,42 @@ module.exports = {
user_Id: 1,
content_Id: 1,
},
{
user_Id: 1,
content_Id: 2,
},
{
user_Id: 2,
content_Id: 3,
},
{
user_Id: 3,
content_Id: 4,
},
{
user_Id: 4,
content_Id: 5,
},
{
user_Id: 5,
content_Id: 6,
},
{
user_Id: 2,
content_Id: 7,
},
{
user_Id: 5,
content_Id: 8,
},
{
user_Id: 1,
content_Id: 9,
},
{
user_Id: 3,
content_Id: 10,
},
],
{}
);
Expand Down