test
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user