+
);
}
diff --git a/client/src/Pages/AdminRoutes.jsx b/client/src/Pages/AdminRoutes.jsx
index 6bc82d9..eb11cca 100644
--- a/client/src/Pages/AdminRoutes.jsx
+++ b/client/src/Pages/AdminRoutes.jsx
@@ -50,11 +50,11 @@ export default function AdminRoute() {
); // Show a loading state while checking user role
} else {
- if ((user && user.role === "admin") || "student") {
+ if ((user && user.role === "admin") ) {
return
+
You are not authorized to access this page
diff --git a/client/src/alan.jsx b/client/src/alan.jsx
index 0746109..7c8f443 100644
--- a/client/src/alan.jsx
+++ b/client/src/alan.jsx
@@ -1,49 +1,53 @@
-// alan-ai-setup.js
import React, { useEffect } from 'react';
const AlanAIProjectKey = "b65ec1671e0e235364a5a62bdae65be32e956eca572e1d8b807a3e2338fdd0dc/stage";
function AlanAIComponent() {
useEffect(() => {
- // Load Alan AI script asynchronously when the component mounts on the client side
-
- //extended additional design to fix the overflow of chatwrapper by fixing to 90% of the parent
- const additionalStyles = `
- .alanBtn-root {
- right: 46px !important;
- bottom: 150px !important;
- }
- #alan-text-chat-wrapper{
- height: 95%;
- bottom: 0px;
- position: fixed;
- }
- `
- ;
-
- const styleTag = document.createElement('style');
- styleTag.innerHTML = additionalStyles;
- document.head.appendChild(styleTag);
-
- // Initialize Alan AI and handle commands once the script is loaded
- /* global alanBtn */
- var alanBtnInstance = alanBtn({
- key: AlanAIProjectKey,
- onCommand: function (commandData) {
- if (commandData && commandData.command === 'openURL') {
- if (commandData.target === '_blank') {
- window.open(commandData.url, '_newtab' + Math.floor(Math.random() * 999999));
- } else {
- window.location.href = commandData.url;
+ // Load Alan AI script dynamically
+ const script = document.createElement("script");
+ script.src = "https://studio.alan.app/web/lib/alan_lib.min.js";
+ script.async = true;
+ script.onload = () => {
+ // Ensure alanBtn is available
+ if (window.alanBtn) {
+ window.alanBtn({
+ key: AlanAIProjectKey,
+ onCommand: (commandData) => {
+ if (commandData && commandData.command === 'openURL') {
+ if (commandData.target === '_blank') {
+ window.open(commandData.url, '_newtab' + Math.floor(Math.random() * 999999));
+ } else {
+ window.location.href = commandData.url;
+ }
}
}
- }
- });
-
+ });
+ } else {
+ console.error("Alan AI SDK failed to load.");
+ }
+ };
+ document.body.appendChild(script);
+
+ // Additional styles to fix chat wrapper overflow
+ const additionalStyles = `
+ .alanBtn-root {
+ right: 46px !important;
+ bottom: 150px !important;
+ }
+ #alan-text-chat-wrapper {
+ height: 95%;
+ bottom: 0px;
+ position: fixed;
+ }
+ `;
+ const styleTag = document.createElement('style');
+ styleTag.innerHTML = additionalStyles;
+ document.head.appendChild(styleTag);
+
}, []);
-
- return
; // This div will serve as the mount point for the Alan AI button
+ return
; // Mount point for Alan AI button
}
export default AlanAIComponent;
diff --git a/server/.env.example b/server/.env.example
index d288088..b85b94b 100644
--- a/server/.env.example
+++ b/server/.env.example
@@ -1,3 +1,3 @@
-TOKEN_KEY=yourSecretKey
-MONGO_URL=mongodb://127.0.0.1:27017/ElectiveHub
+TOKEN_KEY=electivehub
+MONGO_URL="mongodb://127.0.0.1:27017/ElectiveHub"
PORT=4000
\ No newline at end of file
diff --git a/server/Controllers/AuthController.js b/server/Controllers/AuthController.js
index eb81d20..05adc00 100644
--- a/server/Controllers/AuthController.js
+++ b/server/Controllers/AuthController.js
@@ -5,8 +5,12 @@ const bcrypt = require("bcryptjs");
module.exports.Signup = async (req, res, next) => {
try {
const { email, password, username, createdAt,role } = req.body;
-
- const existingUser = await User.findOne({ email });
+ // console.log(req.body);
+ if(!email || !password || !username){
+ return res.json({message:'All fields are required'})
+ }
+ // const existingUser = await User.findOne({ email });
+ console.log(existingUser);
if (existingUser) {
return res.json({ message: "User already exists" });
}
diff --git a/server/app.js b/server/app.js
index 1b62e60..e121137 100644
--- a/server/app.js
+++ b/server/app.js
@@ -13,14 +13,15 @@ const FeedbackRoute = require("./Routes/FeedbackRoutes");
require("dotenv").config();
const { MONGO_URL, PORT } = process.env;
-
+console.log(MONGO_URL);
mongoose
.connect(MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
- .then(() => console.log("MongoDB is connected successfully"))
+ .then(() => console.log("MongoDB is connected successfully"))
.catch((err) => console.error(err));
+
const allowedOrigins = [
"http://127.0.0.1:5173",
"http://localhost:5173",
@@ -28,23 +29,25 @@ const allowedOrigins = [
"https://electivehub.onrender.com",
// Add more URLs as needed
];
+
app.use(cookieParser());
+// Set up CORS with allowed origins and credentials
app.use(
cors({
- origin: allowedOrigins,
-
+ origin: function (origin, callback) {
+ // Allow requests with no origin (like mobile apps or curl requests)
+ if (!origin) return callback(null, true);
+ if (allowedOrigins.indexOf(origin) !== -1) {
+ callback(null, true);
+ } else {
+ callback(new Error("Not allowed by CORS"));
+ }
+ },
credentials: true,
})
);
-// const corsOrigin ={
-// origin:'http://127.0.0.1:5173', //or whatever port your frontend is using
-// credentials:true,
-// optionSuccessStatus:200
-// }
-// app.use(cors(corsOrigin));
-
app.use(express.json());
app.use("/auth", authRoute);
@@ -55,18 +58,19 @@ app.use(
);
app.use("/student", authMiddleware(["admin", "user", "student"]), StudentRoute);
app.use("/subject", authMiddleware(["admin", "user", "student"]), SubjectRoute);
+
app.get("/yaae", authMiddleware(["admin", "user", "student"]), (req, res) => {
res.json({ status: true, user: req.user });
});
+
app.use("/feedback", FeedbackRoute);
app.post("/subscribe-newsletter", async (req, res) => {
try {
const { email } = req.body;
const publicationId = "64f31498352b1c82180c69aa"; // Your publication ID
- console.log(email);
- console.log(publicationId);
- // Make the API call to subscribe to the newsletter
+ console.log(email, publicationId);
+
const response = await axios.post(
"https://electivehub.hashnode.dev/api/newsletter/subscribe",
{
@@ -75,7 +79,7 @@ app.post("/subscribe-newsletter", async (req, res) => {
}
);
console.log(response);
- // Handle the response from the API call
+
if (response.status === 200) {
res
.status(200)
@@ -84,14 +88,15 @@ app.post("/subscribe-newsletter", async (req, res) => {
res.status(500).json({ error: "Error subscribing to the newsletter" });
}
} catch (error) {
- console.log(error);
+ console.error(error);
res.status(500).json({ error: "Error subscribing to the newsletter" });
}
});
-app.listen(PORT, () => {
- console.log(`Server is listening on port ${PORT}`);
-});
app.get("/", (req, res) => {
res.send("dsjdnjsd");
});
+
+app.listen(PORT, () => {
+ console.log(`Server is listening on port ${PORT}`);
+});