Skip to content

Commit

Permalink
bit refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesbrandenburger committed Jan 22, 2024
1 parent 9388aaa commit 5bf2817
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 15 deletions.
3 changes: 0 additions & 3 deletions services/analytics-service/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import express from "express";
import { MongoClient } from "mongodb";
import cookieParser from 'cookie-parser';
import auth from "./auth-middleware.js";

// use .env file in parent directory (only needed for local development)
import dotenv from "dotenv";
Expand All @@ -16,15 +15,13 @@ await client.connect();
const database = client.db("reveal-the-world");

// setup collections
// analyticsState = { timestamp: string, bestVisitedRegionInTheLastMonth: string, amountOfPinsTotal: number, amountOfPinsLastMonth: number }
const analyticsStateCollection = database.collection("analytics");

// start express server
const app = express();
const port = 3004;
app.use(express.json());
app.use(cookieParser());
// app.use(auth);

// define routes
app.get("/:tenant", async (req, res) => {
Expand Down
9 changes: 2 additions & 7 deletions services/auth-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const appURL = process.env.appURL;
const fusionAuthURL = process.env.fusionAuthURL;
const internalFusionAuthURL = process.env.internalFusionAuthURL;

// Validate the token signature, make sure it wasn't expired
// validate the token signature, make sure it wasn't expired
const validateUser = async (userTokenCookie) => {
// Make sure the user is authenticated.
if (!userTokenCookie || !userTokenCookie?.access_token) {
Expand All @@ -51,7 +51,6 @@ const validateUser = async (userTokenCookie) => {
}
}


const getKey = async (header, callback) => {
const jwks = jwksClient({
jwksUri: `${internalFusionAuthURL}/.well-known/jwks.json`
Expand Down Expand Up @@ -136,6 +135,7 @@ app.get('/oauth-redirect', async (req, res, next) => {
}
const accessToken = response.successResponse;

//
if (!accessToken.access_token) {
console.error('Failed to get Access Token')
return;
Expand All @@ -144,19 +144,16 @@ app.get('/oauth-redirect', async (req, res, next) => {

// Exchange Access Token for User
response = await client.retrieveUserUsingJWT(accessToken.access_token);

if (response.statusCode !== 200) {
console.error('Failed to get User from access token, redirecting home.');
res.redirect(302, tenantToPath(tenant));
}
const userResponse = response.successResponse;

if (!userResponse?.user) {
console.error('Failed to get User from access token, redirecting home.');
res.redirect(302, tenantToPath(tenant));
}
res.cookie(`${tenant}-${userDetails}`, userResponse.user);

res.redirect(302, tenantToPath(tenant));
} catch (err) {
console.error(err);
Expand All @@ -168,7 +165,6 @@ app.get('/oauth-redirect', async (req, res, next) => {

app.get('/logout', (req, res, next) => {
const clientId = `${req.query?.clientId}`;

res.redirect(302, `${fusionAuthURL}/oauth2/logout?client_id=${clientId}`);
});

Expand All @@ -183,7 +179,6 @@ app.get('/oauth2/logout', (req, res, next) => {
console.log('Logging out...')
res.clearCookie(`${tenant}-${userToken}`);
res.clearCookie(`${tenant}-${userDetails}`);

res.redirect(302, tenantToPath(tenant));
});

Expand Down
2 changes: 0 additions & 2 deletions services/heatmap-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ const app = express();
const port = 3003;
app.use(express.json());
app.use(cookieParser());
// app.use(auth);


// define routes
app.get("/", async (req, res) => {
Expand Down
3 changes: 0 additions & 3 deletions services/update-service/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import express from "express";
import { MongoClient } from "mongodb";
import cookieParser from 'cookie-parser';
import auth from "./auth-middleware.js";

// use .env file in parent directory (only needed for local development)
import dotenv from "dotenv";
Expand All @@ -18,7 +17,6 @@ const database = client.db("reveal-the-world");
// setup collections
const pinCollection = database.collection("pin");
const polygonCollection = database.collection("polygon");
// heatRegionsState = { timestamp: string, heatRegions: [{ polygonname: string, density: number (0-1), count: number }] }
const heatRegionStateCollection = database.collection("heatRegionState");
const analyticsStateCollection = database.collection("analytics");

Expand All @@ -28,7 +26,6 @@ const app = express();
const port = 3005;
app.use(express.json());
app.use(cookieParser());
// app.use(auth);

const debug = (...args) => { console.log(...args); };

Expand Down

0 comments on commit 5bf2817

Please sign in to comment.