-
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 'frontend' 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.