Skip to content

Commit 8384c2f

Browse files
committed
feat: Implement real-time wallet updates via WebSockets and streamline authentication token handling.
1 parent 403f9a6 commit 8384c2f

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

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
})

0 commit comments

Comments
 (0)