Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User authentication does not work #61

Open
dipyamanroy opened this issue Jul 22, 2024 · 2 comments
Open

User authentication does not work #61

dipyamanroy opened this issue Jul 22, 2024 · 2 comments

Comments

@dipyamanroy
Copy link

dipyamanroy commented Jul 22, 2024

Expected Behavior

All routes are user authenticated.

Current Behavior

If the path of internal routes is known they are just accessible without verifying whether the user exists or not, in the MongoDB database.

image

How to ensure the routes are only available via registered users?

@dipyamanroy
Copy link
Author

Possible Solution

As suggested by @saipreetham123, within app.js move the line:

app.use(express.static('public'));

below the other use statements. And add a conditional middleware:

const excludedRoutes = ['/', '/register', '', '/login'];

app.use((req, res, next) => { 
  console.log(req.path);
  if (excludedRoutes.includes(req.path)) {
    next();
  } else {
    validateToken(req, res, next);
  }
});

image

@snoopysecurity
Copy link
Owner

Hi, are these just the client side pages such as http://dvws.local/upload.html, http://dvws.local/notes.html etc? these pages can be viewed unauthenticated but the data for this pages are coming from /api, and that will require an API token

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants