test
This commit is contained in:
@@ -11,6 +11,7 @@ import { formatDistanceToNow } from "date-fns";
|
||||
import axios from "axios";
|
||||
import { toast } from "sonner";
|
||||
import { ArrowLeft, Send, RefreshCw } from "lucide-react";
|
||||
import { getCookie } from "@/lib/client-utils";
|
||||
|
||||
interface Message {
|
||||
_id: string;
|
||||
@@ -44,7 +45,24 @@ export default function ChatDetail({ chatId }: { chatId: string }) {
|
||||
// Fetch chat data
|
||||
const fetchChat = async () => {
|
||||
try {
|
||||
const response = await axios.get(`/api/chats/${chatId}`);
|
||||
// Get auth token from cookies
|
||||
const authToken = getCookie("Authorization");
|
||||
|
||||
if (!authToken) {
|
||||
toast.error("You need to be logged in");
|
||||
router.push("/auth/login");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up axios with the auth token
|
||||
const authAxios = axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_API_URL,
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`
|
||||
}
|
||||
});
|
||||
|
||||
const response = await authAxios.get(`/chats/${chatId}`);
|
||||
setChat(response.data);
|
||||
setLoading(false);
|
||||
} catch (error) {
|
||||
@@ -76,7 +94,24 @@ export default function ChatDetail({ chatId }: { chatId: string }) {
|
||||
|
||||
setSending(true);
|
||||
try {
|
||||
await axios.post(`/api/chats/${chatId}/message`, {
|
||||
// Get auth token from cookies
|
||||
const authToken = getCookie("Authorization");
|
||||
|
||||
if (!authToken) {
|
||||
toast.error("You need to be logged in");
|
||||
router.push("/auth/login");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up axios with the auth token
|
||||
const authAxios = axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_API_URL,
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`
|
||||
}
|
||||
});
|
||||
|
||||
await authAxios.post(`/chats/${chatId}/message`, {
|
||||
content: message
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user