diff --git a/README.md b/README.md index e7ddfdc..7583717 100644 --- a/README.md +++ b/README.md @@ -1 +1,4 @@ -# AI Messenger \ No newline at end of file +# AI Chatbot + +## 👋 Introduction +Welcome to the **AI Chatbot**! This application allows users to interact with an AI-powered chatbot using natural language. Built with React and Node, it offers a seamless experience for engaging in conversations with an intelligent virtual assistant. \ No newline at end of file diff --git a/backend/passport_conf.js b/backend/passport_conf.js index d4f8be3..06437e0 100644 --- a/backend/passport_conf.js +++ b/backend/passport_conf.js @@ -1,7 +1,6 @@ import 'dotenv/config' -import passport from 'passport'; -import { Strategy } from 'passport-google-oauth20'; - +import passport from 'passport' +import { Strategy } from 'passport-google-oauth20' const conf = { clientID: process.env.clientID, @@ -14,4 +13,4 @@ passport.use(new Strategy(conf, (req, aToken, rToken, pro, done) => done(null, p passport.serializeUser((user, done) => done(null, user)) -passport.deserializeUser((user, done) => done(null, user)) +passport.deserializeUser((user, done) => done(null, user)) \ No newline at end of file diff --git a/backend/server.js b/backend/server.js index f8c981f..739a7fb 100644 --- a/backend/server.js +++ b/backend/server.js @@ -4,34 +4,33 @@ import './passport_conf.js' import express from 'express' import passport from 'passport' import session from 'express-session' - import { GoogleGenerativeAI } from "@google/generative-ai" // Access your API key as an environment variable (see "Set up your API key" above) -const genAI = new GoogleGenerativeAI(process.env.geminiKey); - +const genAI = new GoogleGenerativeAI(process.env.geminiKey) -const app = express(); +const app = express() const PORT = process.env.PORT + app.use(cors({credentials: true, origin: true})) app.use(express.json()) + // express session app.use(session({ secret: process.env.secret, resave: false, saveUninitialized: false -})); +})) - -app.use(passport.initialize()); -app.use(passport.session()); +app.use(passport.initialize()) +app.use(passport.session()) // Middleware used in protected routes to check if the user has been authenticated const isLoggedIn = (req, res, next) => { if (req.user) { - next(); + next() } else { - res.sendStatus(401); + res.sendStatus(401) } } @@ -43,7 +42,7 @@ app.get("/home", (req, res) => { // Google Auth consent screen route app.get('/google', passport.authenticate('google', { scope: ['email', 'profile'] } - )); + )) // Call back route app.get('/google/callback', @@ -52,17 +51,17 @@ app.get('/google/callback', }), (req, res) => { res.redirect('http://localhost:5173/messages') } -); +) -// failed route if the authentication fails +// Failed route if the authentication fails app.get("/failed", (req, res) => { - console.log('User is not authenticated'); + console.log('User is not authenticated') res.send("Failed") }) // Success route if the authentication is successful app.get("/success",isLoggedIn, (req, res) => { - console.log('You are logged in'); + console.log('You are logged in') res.send(`Welcome ${req.user.displayName}, your userID is ${req.user.id}`) }) @@ -74,15 +73,15 @@ app.get("/userdata", (req, res) => { app.get("/logout", (req, res) => { req.session.destroy((err) => { if (err) { - console.log('Error while destroying session:', err); + console.log('Error while destroying session:', err) } else { req.logout(() => { - console.log('You are logged out'); - res.redirect('/home'); - }); + console.log('You are logged out') + res.redirect('/home') + }) } - }); -}); + }) +}) const talkToAi = async (text) => { const model = genAI.getGenerativeModel({ model: "gemini-pro"}) @@ -97,5 +96,4 @@ app.post("/api", isLoggedIn, async (req, res) => { res.json({message: resp}) }) -app.listen(PORT, () => console.log("server running on port" + PORT)) - +app.listen(PORT, () => console.log("server running on port" + PORT)) \ No newline at end of file