This commit is contained in:
NotII
2025-03-03 21:13:07 +00:00
parent 5260978cb8
commit f5382d82f6
4 changed files with 125 additions and 18 deletions

View File

@@ -24,15 +24,27 @@ export default function NewChatForm() {
useEffect(() => {
const fetchVendorStores = async () => {
try {
const vendorId = getCookie("vendorId");
// Get auth token from cookies
const authToken = getCookie("Authorization");
if (!vendorId) {
if (!authToken) {
toast.error("You need to be logged in");
router.push("/login");
router.push("/auth/login");
return;
}
const response = await axios.get(`/api/stores/vendor/${vendorId}`);
// Set up axios with the auth token
const authAxios = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL,
headers: {
Authorization: `Bearer ${authToken}`
}
});
// Get vendor ID (placeholder until proper JWT decoding)
const vendorId = "current"; // Replace with actual ID extraction
const response = await authAxios.get(`/stores/vendor/${vendorId}`);
setVendorStores(response.data);
if (response.data.length > 0) {
@@ -61,7 +73,24 @@ export default function NewChatForm() {
setLoading(true);
try {
const response = await axios.post("/api/chats/create", {
// 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.post("/chats/create", {
buyerId,
storeId: selectedStore,
initialMessage