Skip to content
3 changes: 2 additions & 1 deletion Admin/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ function App() {

try {
const response = await axios.post(
"http://localhost:3000/api/v1/admin/checkToken",
`${import.meta.env.VITE_SERVER_URL}/api/v1/admin/checkToken`,
{},
{
withCredentials : true ,
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
Expand Down
1 change: 1 addition & 0 deletions Admin/src/Components/AddEvents/AddEvents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const AddEvents = () => {
};

const response = await axios.post(`${import.meta.env.VITE_SERVER_URL}/api/v1/admin/event`, eventData, {
withCredentials : true ,
headers: {
"Authorization": `Bearer ${localStorage.getItem("token")}`,
"Content-Type": "application/json",
Expand Down
4 changes: 3 additions & 1 deletion Admin/src/Login-Register/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const Login = () => {
if (loginData.email === "" || loginData.password === "") return;

try {
const payload = await axios.post(`${import.meta.env.VITE_SERVER_URL}/api/v1/admin/signin`, loginData);
const payload = await axios.post(`${import.meta.env.VITE_SERVER_URL}/api/v1/admin/signin`, loginData , {
withCredentials: true,
});
if (payload.status === 200) {
localStorage.setItem("token", payload.data.token);
localStorage.removeItem("events")
Expand Down
4 changes: 3 additions & 1 deletion Admin/src/Login-Register/Register/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const Register = () => {
// console.log("what is the problem")
const payload = await axios.post(
`${import.meta.env.VITE_SERVER_URL}/api/v1/admin/signup`,
registerData
registerData , {
withCredentials: true,
}
);
if (payload.status === 200) {
toast.success("Account created successfully!");
Expand Down
1 change: 1 addition & 0 deletions Admin/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import react from '@vitejs/plugin-react-swc'

// https://vite.dev/config/
export default defineConfig({
outDir: "dist",
plugins: [react()],
})
47 changes: 31 additions & 16 deletions Backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,44 @@ import cookieParser from "cookie-parser";
import cors from 'cors'
import userRouter from "./routes/user.js";
const app = express();
const allowedOrigins = ["https://hyd-events-website-admin.onrender.com"];

app.use(
cors({
origin: function (origin, callback) {
if (!origin || allowedOrigins.includes(origin)) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS"));
}
},
credentials: true, // Allow cookies & authentication headers if needed
})
);
const port = process.env.PORT || 3000 ;

// Improved CORS configuration
const allowedOrigins = [
"https://hyd-events-website-admin.onrender.com",
"https://hydevents-main.onrender.com",
"https://hyd-events-website.onrender.com",
];

app.use((req, res, next) => {
const origin = req.headers.origin;

// Check if the origin is in our allowed list
if (allowedOrigins.includes(origin)) {
res.setHeader("Access-Control-Allow-Origin", origin);
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
res.setHeader("Access-Control-Allow-Credentials", "true");
}

// Handle preflight requests
if (req.method === "OPTIONS") {
res.writeHead(204);
res.end();
return;
}

next();
});

app.use(cookieParser());
app.use(express.json());

app.use("/api/v1/admin", adminRouter);
app.use("/api/v1/user" , userRouter);

app.listen(3000, () => {
console.log("Server is running on port 3000");
app.listen(port , () => {
console.log(`Server is running on port ${port}`);
});


Expand Down
1 change: 1 addition & 0 deletions Frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import react from '@vitejs/plugin-react-swc'

// https://vitejs.dev/config/
export default defineConfig({
outDir: "dist",
plugins: [react()],
})