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

JWT를 이용한 로그인시 인증 #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 0 additions & 21 deletions User/Entity/LoginUser.js

This file was deleted.

13 changes: 0 additions & 13 deletions User/controller/userController.js

This file was deleted.

26 changes: 0 additions & 26 deletions User/repository/userRepository.js

This file was deleted.

7 changes: 0 additions & 7 deletions User/router/userRouter.js

This file was deleted.

15 changes: 0 additions & 15 deletions User/service/userApplicationService.js

This file was deleted.

35 changes: 18 additions & 17 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@ dotenv.config();
const express = require('express')
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const SingletonContainer = require('./src/Container/SingletonContainer');

const app = express();

app.set('port', process.env.PORT || 4445);
app.use(morgan('dev')); // combined, common, short, tiny
app.use(express.json()); // raw(), text()
app.use(express.urlencoded({extended: false})); // query string, post, put not use stream
app.use(cookieParser(process.env.COOKIE_SECRET)); // cookie 생성은 아니다. 4.3 절을 보자.
app.use(session({
resave: false, // 요청이 올 때 세션에 수정 사항이 생기지 않더라도, 세션을 다시 저장할지?
saveUninitialized: false, // 세션에 저장할 내역이 없더라도 처음부터 세션을 생성할지?
secret: process.env.COOKIE_SECRET, // 4.3절의 session, cookie
cookie: {
httpOnly: true, // 클라이언트에서 쿠키 확인 금지
secure: false, // https가 아닌 환경에서도 사용할 수 있다, 배포시에는 true로 해두어야 한다.
},
name: 'session-cookie',
}));

// 전체 내용을 이해 했다면, use 한곳에 담아보자. 258page

const userRouter = require('./User/Router/userRouter');
app.use('/user', userRouter);
app.use(cookieParser());

const singletonContainer = new SingletonContainer();
const Redis = require('./src/Redis/redis');
const JWTService = require('./src/Auth/jwt/jwt');
const AuthJWT = require('./src/Auth/jwt/authJWT');
const AuthInterface= require('./src/Interface/authInterface');
singletonContainer.register('redis', new Redis());
singletonContainer.register('jwtService', new JWTService(singletonContainer.get('redis')));

const jwtService = singletonContainer.get('jwtService');
const jwtAuthMiddleware = new AuthInterface(new AuthJWT(jwtService));


const userRouter = require('./src/User/Router/userRouter');
app.use('/user', userRouter(jwtAuthMiddleware));

app.get('/', (req, res) => {
res.send('Hello world!');
Expand Down
32 changes: 32 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = [
{
ignores: ["node_modules"],
},
{
files: ["src/**/*.js"],
languageOptions: {
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
},
rules: {
"no-unused-vars": "warn", // 사용하지 않는 변수 경고
"no-console": "warn", // console 사용 금지
"eqeqeq": ["warn", "always"], // === 사용 강제
"semi": ["error", "always"], // 세미콜론 사용 강제
"quotes": ["error", "single"], // 작은 따옴표 사용 강제
"indent": ["error", 4], // 4칸 들여쓰기
"max-len": ["error", { "code": 120 }], // 한 줄 길이 제한
"no-var": "error", // var 사용 금지
"prefer-const": "error", // const 사용 강제
"consistent-return": "error", // 함수에서 일관된 return 사용 강제
"no-shadow": "error", // 변수명 중복 금지
"space-in-parens": ["error", "never"], // 괄호안에 공백을 추가
"array-bracket-spacing": ["error", "always"], // 대괄호 안에 공백을 추가
"object-curly-spacing": ["error", "always"], // 중괄호 안에 공백을 추가
"newline-before-return": "error", // return 문 앞에 한 줄 이상의 공백을 요구
"padded-blocks": ["error", { "blocks": "never" }], // 모든 블록 앞뒤에 빈 줄 추가
},
},
];
Loading
Loading