-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_config.js
More file actions
42 lines (37 loc) · 1 KB
/
auth_config.js
File metadata and controls
42 lines (37 loc) · 1 KB
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
const jwt = require("jsonwebtoken");
const User = require("./models/User");
const saveUser = async function (req, res, next) {
// This will store the user identity claims in the session.
const user = req.openidTokens.claims();
user.userId = user.sub;
if (user) {
User.findOneAndUpdate({ email: user.email }, user, {
upsert: true,
new: true,
})
.lean()
.then((user) => {
jwt.sign(user, process.env.JWT_SECRET, (err, token) => {
res.cookie("user", token).redirect("/app");
});
})
.catch((err) => {
console.log(err);
next();
});
} else {
console.log(err);
res.redirect("/login");
}
};
const config = {
required: false,
auth0Logout: true,
baseURL: process.env.BASE_URL,
issuerBaseURL: "https://prodigy-gate.auth0.com",
clientID: process.env.CLIENT_ID,
redirectUriPath: "app",
handleCallback: saveUser,
appSessionSecret: process.env.APP_SESSION_SECRET_AUTH,
};
module.exports.config = config;