From 956ede5619c6de5ddfabff537ce3be7f48f7f36a Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Mon, 28 Apr 2025 13:14:16 -0700 Subject: [PATCH] added current user api --- auth-service/routes/auth.js | 8 ++++++++ auth-service/server.js | 14 +++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/auth-service/routes/auth.js b/auth-service/routes/auth.js index b735b83..4e87d0b 100644 --- a/auth-service/routes/auth.js +++ b/auth-service/routes/auth.js @@ -10,6 +10,14 @@ router.get( }) ); +router.get('/current_user', (req, res) => { + if (req.isAuthenticated()) { + res.json(req.user); + } else { + res.status(401).json({ error: 'Not authenticated' }); + } +}); + router.get("/login", (req, res) => { if (req.user) { diff --git a/auth-service/server.js b/auth-service/server.js index 2fd4f75..6c20d5e 100644 --- a/auth-service/server.js +++ b/auth-service/server.js @@ -23,13 +23,13 @@ app.use( app.use(passport.initialize()); app.use(passport.session()); -// app.use( -// cors({ -// origin: process.env.ACCEPTED_ORIGINS.split(","), -// methods: "GET", -// credentials: true, -// }) -// ) +app.use( + cors({ + origin: process.env.ACCEPTED_ORIGINS.split(","), + methods: "GET", + credentials: true, + }) +) app.use("/auth", authRoute);