Basic Authentication using 'express-basic-auth' middleware

// Import required modules
const express = require('express');
const app = express();
const basicAuth = require('express-basic-auth');

// Define a user for basic authentication
const users = { 'username': 'password' };

// Use express-basic-auth middleware for authentication
app.use(basicAuth({ users }));

// Define a route accessible only to authenticated users
app.get('/secure', (req, res) => {
  res.send('Authenticated route');
});

Continue Reading

Handpicked posts just for you — based on your current read.

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!