repl.it
@Coder100/

Repl Auth Express

Nodejs

Yaaaa

fork
loading
Files
  • index.js
  • views
  • Packager files
  • package-lock.json
  • package.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// SET UP SERVER
let app = require('express')();
let bodyParser = require('body-parser');
app.set('view engine', 'pug');
app.use(bodyParser.urlencoded({ extended: true }));

//GET HOME PAGE
app.get('/', function(req, res) {
  // CHECK IF HEADERS ARE SET
	if (req.get('X-Replit-User-Id')) {
		res.render('index', {
		  // GIVE ALL THE KNOWN USER INFORMATION
			user: {
				id: req.get('X-Replit-User-Id'),
				name: req.get('X-Replit-User-Name'),
				roles: req.get('X-Replit-User-Roles')
			}
		});
  // OTHERWISE, DISPLAY PROMPT TO LOG IN
	} else {
		res.render('index', {
			user: false
		});
	}
});

// LISTEN ON PORT 8080
app.listen(8080);
Fetching token
?