-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
44 lines (38 loc) · 1.16 KB
/
app.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import dotenv from "dotenv";
dotenv.config();
import { setupKinde, protectRoute, getUser, GrantType } from "@kinde-oss/kinde-node-express";
import express from "express";
const app = express();
const port = 3000;
app.use(express.static("public"));
const config = {
grantType: GrantType.AUTHORIZATION_CODE,
clientId: process.env.KINDE_CLIENT_ID,
issuerBaseUrl: process.env.KINDE_ISSUER_URL,
siteUrl: process.env.KINDE_SITE_URL,
secret: process.env.KINDE_CLIENT_SECRET,
redirectUrl: process.env.KINDE_REDIRECT_URL,
unAuthorisedUrl: process.env.KINDE_SITE_URL,
postLogoutRedirectUrl: process.env.KINDE_POST_LOGOUT_REDIRECT_URL,
};
app.set("view engine", "pug");
const client = setupKinde(config, app);
app.get("/", async (req, res) => {
if (await client.isAuthenticated(req)) {
res.redirect("/admin");
} else {
res.render("index", {
title: "Hey",
message: "Hello there! what would you like to do?",
});
}
});
app.get("/admin", protectRoute, getUser, (req, res) => {
res.render("admin", {
title: "Admin",
user: req.user,
});
});
app.listen(port, () => {
console.log(`Kinde Express Starter Kit listening on port ${port}!`);
});