Skip to content

Commit

Permalink
Merge pull request #30 from vanthaita/feat-auth
Browse files Browse the repository at this point in the history
feat: add middleware, update message component type
  • Loading branch information
LeeinUITk17 authored Sep 12, 2024
2 parents cf20a04 + 225667a commit 0c36de1
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 310 deletions.
5 changes: 2 additions & 3 deletions Server/src/Gateway/chat.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
);

try {
// console.log('Content: ', message);
const sending = await this.chatService.sendMessage(
parseInt(message.roomId, 10),
userProfile.id,
message.message,
);

this.server.to(message.roomId).emit('receiveMessage', {
id: userProfile.id + message.roomId + message.message.length,
id: sending.id,
createdAt: sending.createdAt,
roomId: 1,
message: message.message,
Expand Down Expand Up @@ -151,4 +150,4 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
client.emit('error', { message: 'Failed to leave room' });
}
}
}
}
9 changes: 5 additions & 4 deletions Server/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ export class AuthController {
const authRes = await this.authService.authenticate(googleToken);

res.cookie('access_token', authRes.access_token, { httpOnly: true });
res.send({
message: 'Successfully logged in',
access_token: authRes.access_token,
});
res.redirect(`${process.env.Client_URL}/messages`);
// res.send({
// message: 'Successfully logged in',
// access_token: authRes.access_token,
// });
}

@UseGuards(JWTAuthGuard)
Expand Down
4 changes: 2 additions & 2 deletions Server/src/chat/chat.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
import { ChatService } from './chat.service';
import { CreateChatDto } from './dto/create-chat.dto';
import { UpdateChatDto } from './dto/update-chat.dto';
Expand All @@ -17,7 +17,7 @@ export class ChatController {
}

@Get(':roomId')
async getMessagesByRoom(@Param('roomId') roomId: number) {
async getMessagesByRoom(@Query('roomId') roomId: number) {
return this.chatService.getMessagesByRoom(roomId);
}
}
76 changes: 0 additions & 76 deletions client/src/app/chat/Chat.module.css

This file was deleted.

168 changes: 0 additions & 168 deletions client/src/app/chat/chat.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions client/src/app/chat/page.tsx

This file was deleted.

33 changes: 18 additions & 15 deletions client/src/app/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Link from "next/link";
import ButtonSupport from "@/components/ButtonSupport";
import { Button } from "@/components/ui/button";
// A simple error boundary to show a nice error page if something goes wrong (Error Boundary)
// Users can contanct support, go to the main page or try to reset/refresh to fix the error
export default function Error({
Expand Down Expand Up @@ -151,22 +152,24 @@ export default function Error({
</svg>
Refresh
</button>
<ButtonSupport />
<Link href="/" className="btn btn-sm">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
className="w-5 h-5"
>
<path
fillRule="evenodd"
d="M9.293 2.293a1 1 0 011.414 0l7 7A1 1 0 0117 11h-1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-3a1 1 0 00-1-1H9a1 1 0 00-1 1v3a1 1 0 01-1 1H5a1 1 0 01-1-1v-6H3a1 1 0 01-.707-1.707l7-7z"
clipRule="evenodd"
/>
</svg>
Home
<Link href="/">
<Button className="flex justify-center items-center">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
className="w-5 h-5"
>
<path
fillRule="evenodd"
d="M9.293 2.293a1 1 0 011.414 0l7 7A1 1 0 0117 11h-1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-3a1 1 0 00-1-1H9a1 1 0 00-1 1v3a1 1 0 01-1 1H5a1 1 0 01-1-1v-6H3a1 1 0 01-.707-1.707l7-7z"
clipRule="evenodd"
/>
</svg>
<span className="ml-2">Home</span>
</Button>
</Link>
<ButtonSupport />
</div>
</div>
</>
Expand Down
Loading

0 comments on commit 0c36de1

Please sign in to comment.