Skip to content

Commit ea0d61c

Browse files
authored
Merge pull request #21 from sinwoojin/fix/edit-ssrFetch-call
Fix/edit ssr fetch call
2 parents 5e21e8b + fb02e1e commit ea0d61c

File tree

16 files changed

+365
-122
lines changed

16 files changed

+365
-122
lines changed

backend/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ Content-Type: application/json
8585
```bash
8686
# 잔액 조회
8787
GET /wallet/balance
88-
Authorization: Bearer {access_token}
88+
Authorization: Bearer {accessToken}
8989

9090
# 코인 구매
9191
POST /wallet/buy
92-
Authorization: Bearer {access_token}
92+
Authorization: Bearer {accessToken}
9393
Content-Type: application/json
9494
{
9595
"coinId": "bitcoin",

backend/src/auth/auth.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class AuthController {
1313
}
1414

1515
@Post('login')
16-
async login(@Body() body: { email: string; password: string }):Promise<{access_token: string; user: LoginUser}> {
16+
async login(@Body() body: { email: string; password: string }):Promise<{accessToken: string; user: LoginUser}> {
1717
console.log('📌 Login request body:', body);
1818

1919
const user = await this.authService.validateUser(body.email, body.password);

backend/src/auth/auth.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ import { JwtStrategy } from './jwt.strategy';
1515
],
1616
providers: [AuthService, JwtStrategy],
1717
controllers: [AuthController],
18-
exports: [AuthService],
18+
exports: [AuthService, JwtModule, JwtStrategy],
1919
})
2020
export class AuthModule {}

backend/src/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class AuthService {
4949
async login(user: LoginUser) {
5050
const payload = { email: user.email, sub: user.id };
5151
return {
52-
access_token: this.jwtService.sign(payload),
52+
accessToken: this.jwtService.sign(payload),
5353
user,
5454
};
5555
}

backend/src/events/events.gateway.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
OnGatewayConnection,
33
OnGatewayDisconnect,
4+
SubscribeMessage,
45
WebSocketGateway,
56
WebSocketServer,
67
} from '@nestjs/websockets';
@@ -19,9 +20,14 @@ export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
1920
console.log(`Client disconnected: ${client.id}`);
2021
}
2122

23+
@SubscribeMessage('joinUserRoom')
24+
handleJoinRoom(client: Socket, userId: string) {
25+
client.join(`user-${userId}`);
26+
console.log(`User ${userId} joined room user-${userId}`);
27+
return { success: true };
28+
}
29+
2230
sendWalletUpdate(userId: string, newBalance: number) {
23-
// In a real app, you'd target the specific user's socket room
24-
// For this demo, we'll just broadcast or emit to a room named after userId
2531
this.server
2632
.to(`user-${userId}`)
2733
.emit('walletUpdate', { balance: newBalance });

backend/src/wallet/wallet.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Module } from '@nestjs/common';
2+
import { AuthModule } from 'src/auth/auth.module';
23
import { DatabaseModule } from '../database/database.module';
34
import { EventsModule } from '../events/events.module';
45
import { WalletController } from './wallet.controller';
56
import { WalletService } from './wallet.service';
67

78
@Module({
8-
imports: [DatabaseModule, EventsModule],
9+
imports: [DatabaseModule, EventsModule, AuthModule],
910
providers: [WalletService],
1011
controllers: [WalletController],
1112
})

backend/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ echo $REGISTER_RESPONSE
99
echo "Logging in..."
1010
LOGIN_RESPONSE=$(curl -s -X POST http://localhost:3000/auth/login -H "Content-Type: application/json" -d '{"email": "test@example.com", "password": "password123"}')
1111
echo $LOGIN_RESPONSE
12-
TOKEN=$(echo $LOGIN_RESPONSE | grep -o '"access_token":"[^"]*' | grep -o '[^"]*$')
12+
TOKEN=$(echo $LOGIN_RESPONSE | grep -o '"accessToken":"[^"]*' | grep -o '[^"]*$')
1313
echo "Token: $TOKEN"
1414

1515
# Get Balance

frontend/package-lock.json

Lines changed: 137 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"react-hook-form": "^7.60.0",
5757
"react-resizable-panels": "^2.1.7",
5858
"recharts": "2.15.4",
59+
"socket.io-client": "^4.8.1",
5960
"sonner": "^1.7.4",
6061
"tailwind-merge": "^3.3.1",
6162
"tailwindcss-animate": "^1.0.7",

frontend/src/app/(auth)/login/page.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ function LoginPage() {
4545

4646
if (response.ok) {
4747
const data = await response.json();
48-
// Context 업데이트 (로컬 스토리지는 Provider가 처리)
49-
if (data.access_token) {
50-
setAccessToken(data.access_token);
48+
if (data.accessToken) {
49+
setAccessToken(data.accessToken);
5150
}
5251
if (data.user) {
5352
setUser(data.user);
5453
}
55-
// 메인 페이지로 이동
5654
router.push("/");
5755
} else {
5856
const data = await response.json();

0 commit comments

Comments
 (0)