Home > Software engineering >  How do I not allow access to the home page without sign-in?
How do I not allow access to the home page without sign-in?

Time:09-03

I'm new in nodeJs, so I prepared a sign in page with the database and it works normally. Now I have prepared a home page, but I notice that the client can access the home page directly without connection in his account by this link http://127.0.0.1:5500/public/Home.html So what should I learn or should I do? Any examples or propositions are welcome.

CodePudding user response:

you should use a middleware to check the user is logged in or not.

for example

const express = require('express');
const router = express.Router();
const Auth = require('../middleware/auth');//require the Auth middleware
 

router.get('/',Auth,async(req,res)=>{
       //here ^^^^^
  //your code...

})

CodePudding user response:

you need authentication

One of the easy and secure way is to user JSON Web Token (JWT)

here

CodePudding user response:

It depends of the framework / language used , for example if its React , you can configure the home route to be accessible only if user is signed in . Give us more details about your code so we can help you further

  • Related