-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/fe/#145-FloatingButton' of https://github.com/b…
…oostcampwm-2024/web28-DDara into feature/fe/#145-FloatingButton
- Loading branch information
Showing
28 changed files
with
700 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const PORT = 3001; |
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,16 @@ | ||
import { loginUser } from '../services/authService.js'; | ||
|
||
export const login = async (req, res) => { | ||
const { id, password } = req.body; | ||
|
||
try { | ||
const token = await loginUser(id, password); | ||
if (!token) { | ||
return res.status(401).json({ message: 'Invalid ID or password' }); | ||
} | ||
return res.status(200).json({ token }); | ||
} catch (error) { | ||
console.error('Login error:', error); | ||
return res.status(500).json({ message: 'Server error occurred' }); | ||
} | ||
}; |
File renamed without changes.
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,9 @@ | ||
import { validationResult } from 'express-validator'; | ||
|
||
export const validationMiddleware = (req, res, next) => { | ||
const errors = validationResult(req); | ||
if (!errors.isEmpty()) { | ||
return res.status(400).json({ errors: errors.array() }); | ||
} | ||
next(); | ||
}; |
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 { pool } from '../db/db.js'; | ||
|
||
export const findUserById = async id => { | ||
const result = await pool.query('SELECT * FROM "main"."user" WHERE id = $1', [id]); | ||
return result.rows[0]; | ||
}; |
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,18 @@ | ||
import express from 'express'; | ||
import { body } from 'express-validator'; | ||
import { login } from '../controllers/authController.js'; | ||
import { validationMiddleware } from '../middleware/validationMiddleware.js'; | ||
|
||
export const authRouter = express.Router(); | ||
|
||
authRouter.post( | ||
'/login', | ||
[ | ||
body('id').notEmpty().withMessage('ID is required'), | ||
body('password') | ||
.isLength({ min: 6 }) | ||
.withMessage('Password must be at least 6 characters long'), | ||
], | ||
validationMiddleware, | ||
login, | ||
); |
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,19 @@ | ||
import bcrypt from 'bcrypt'; | ||
import jwt from 'jsonwebtoken'; | ||
import { findUserById } from '../repositories/userRepository.js'; | ||
|
||
export const loginUser = async (id, password) => { | ||
const user = await findUserById(id); | ||
if (!user) { | ||
throw new Error('User not found'); | ||
} | ||
|
||
const isPasswordValid = await bcrypt.compare(password, user.password); | ||
if (!isPasswordValid) { | ||
throw new Error('Invalid password'); | ||
} | ||
|
||
// JWT 생성 | ||
const token = jwt.sign({ userId: user.id }, process.env.JWT_SECRET, { expiresIn: '1h' }); | ||
return { token, userId: user.id }; | ||
}; |
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,41 @@ | ||
import { WebSocketServer } from 'ws'; | ||
|
||
const activeConnections = {}; // token별로 연결을 관리하기 위한 객체 | ||
|
||
export const initializeWebSocketServer = server => { | ||
const wss = new WebSocketServer({ server }); | ||
|
||
wss.on('connection', (ws, req) => { | ||
// URL에서 token 추출 | ||
// TODO: 프론트 라우터 및 token 설정 완료 후 테스트 | ||
const url = new URL(req.url, `http://${req.headers.host}`); | ||
const token = url.searchParams.get('token'); | ||
|
||
if (!token) { | ||
ws.close(4001, 'Token is required'); | ||
return; | ||
} | ||
|
||
// 동일한 token으로 이미 연결된 클라이언트가 있으면 이전 연결을 강제로 종료 | ||
if (activeConnections[token]) { | ||
activeConnections[token].close(4000, 'Duplicate connection'); | ||
} | ||
|
||
// 새로운 연결을 활성화된 연결 목록에 저장 | ||
activeConnections[token] = ws; | ||
|
||
console.log(`Client connected with token: ${token}`); | ||
|
||
// 클라이언트로부터 메시지 받았을 때의 이벤트 처리 | ||
ws.on('message', message => { | ||
console.log(`Received from ${token}:`, message); | ||
}); | ||
|
||
// 클라이언트 연결 종료 시 | ||
ws.on('close', (code, reason) => { | ||
console.log(`Client disconnected with token: ${token}, Code: ${code}, Reason: ${reason}`); | ||
// 연결이 종료되면 activeConnections에서 해당 token 제거 | ||
delete activeConnections[token]; | ||
}); | ||
}); | ||
}; |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
import { Map } from '@/component/maps/Map.tsx'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import { Main } from '@/pages/Main'; | ||
import { Register } from '@/pages/Register'; | ||
import { AddChannel } from '@/pages/AddChannel'; | ||
import { UserRoute } from '@/pages/UserRoute'; | ||
import { DrawRoute } from '@/pages/DrawRoute'; | ||
import { HostView } from '@/pages/HostView'; | ||
import { GuestView } from '@/pages/GuestView'; | ||
|
||
export const App = () => { | ||
return <Map lat={37.3595704} lng={127.105399} type="naver" />; | ||
}; | ||
const ChannelRoutes = () => ( | ||
<Routes> | ||
<Route path="host" element={<HostView />} /> | ||
<Route path="guest/:guestId" element={<GuestView />} /> | ||
</Routes> | ||
); | ||
|
||
export const App = () => ( | ||
<Routes> | ||
<Route path="/" element={<Main />} /> | ||
<Route path="/register" element={<Register />} /> | ||
<Route path="/add-channel" element={<AddChannel />} /> | ||
<Route path="/add-channel/:user" element={<UserRoute />} /> | ||
<Route path="/add-channel/:user/draw" element={<DrawRoute />} /> | ||
<Route path="/channel/:channelId/*" element={<ChannelRoutes />} /> | ||
</Routes> | ||
); |
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,27 @@ | ||
import { ReactNode } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
interface IDropdownButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { | ||
children: ReactNode; | ||
className?: string; | ||
} | ||
|
||
export const DropdownButton = (props: IDropdownButtonProps) => { | ||
return ( | ||
<button | ||
type={props.type ?? 'button'} | ||
className={classNames( | ||
'flex', | ||
'justify-center', | ||
'items-center', | ||
'bg-transparent', | ||
'w-6', | ||
'h-6', | ||
props.className, | ||
)} | ||
{...props} | ||
> | ||
{props.children} | ||
</button> | ||
); | ||
}; |
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 @@ | ||
export const AddChannel = () => <>Hello</>; |
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 @@ | ||
export const DrawRoute = () => <>Hello</>; |
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 @@ | ||
export const GuestView = () => <>Hello</>; |
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 @@ | ||
export const HostView = () => <>Hello</>; |
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 @@ | ||
export const Main = () => <>Hello</>; |
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 @@ | ||
export const Register = () => <>Hello</>; |
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 @@ | ||
export const UserRoute = () => <>Hello</>; |
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,46 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { fn } from '@storybook/test'; | ||
|
||
import { DropdownButton } from '@/component/common/dropdown/DropdownButton.tsx'; | ||
|
||
import { MdDensityMedium } from 'react-icons/md'; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export | ||
const meta = { | ||
title: 'Dropdown/Button', | ||
component: DropdownButton, | ||
parameters: { | ||
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout | ||
layout: 'centered', | ||
}, | ||
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs | ||
tags: ['autodocs'], | ||
// More on argTypes: https://storybook.js.org/docs/api/argtypes | ||
argTypes: { | ||
children: { | ||
control: 'object', | ||
description: '자식 컴포넌트로 항상 리액트 노드를 넘겨준다.', | ||
table: { | ||
type: { summary: 'ReactNode' }, | ||
}, | ||
required: true, // 설명 목적으로 required 여부는 table 필드로 작성함 | ||
}, | ||
className: { | ||
control: 'text', | ||
description: '테일 윈드 기반의 클래스 이름을 넘겨준다.', | ||
}, | ||
}, | ||
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args | ||
args: { onClick: fn() }, | ||
} satisfies Meta<typeof DropdownButton>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args | ||
export const Default: Story = { | ||
args: { | ||
children: <MdDensityMedium />, | ||
className: '', | ||
}, | ||
}; |
Oops, something went wrong.