Skip to content

Commit e3b803f

Browse files
committed
fix(express): password protection with username
1 parent d0c31ce commit e3b803f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const config = {
2-
passwordProtect: false,
3-
password: "password"
2+
challenge: false,
3+
users: {
4+
// username: 'password', you can add multiple users.
5+
interstellar: 'password',
6+
}
47
}
58
export default config;

index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ const server = http.createServer()
1010
const app = express(server)
1111
const bareServer = createBareServer('/v/')
1212
const PORT = 8080
13-
if (config.passwordProtect) {
14-
console.log("Password protection is enabled. Username is 'interstellar'.")
15-
console.log("Password is: " + config.password)
16-
app.use(basicAuth({
17-
users: { "interstellar" : password },
18-
challenge: true
19-
}))
13+
if (config.challenge) {
14+
console.log("Password protection is enabled. Usernames are: " + Object.keys(config.users))
15+
console.log("Passwords are: " + Object.values(config.users))
16+
app.use(basicAuth(config))
2017
}
2118
app.use(express.json())
2219
app.use(express.urlencoded({ extended: true }))

0 commit comments

Comments
 (0)