-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateAdminToken.js
More file actions
33 lines (24 loc) · 1.08 KB
/
generateAdminToken.js
File metadata and controls
33 lines (24 loc) · 1.08 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
const dotenv = require("dotenv")
dotenv.config()
const jwt = require("jsonwebtoken");
const admin = true; // By default admin is true, if the admin token is not
// specified in the request this app return 403
// For extra security reasons it is recommended to modify the name of the variable or use it in another way, since if a token is created in this way and it is admin true anyone will be able to access the api with that token. For a basic use you can leave it as it is or change it for another name.
const secretkey = process.env.JWT_KEY; // make your own secret
/*
* Creating a token with the secret key and the admin variable.
*/
jwt.sign({ admin }, secretkey, (err, token) => {
try {
if (err) throw err;
const data = {
admin_jwt: {
token: token,
secret_key: secretkey
}
}
console.log(JSON.stringify(data, null, 2));
} catch (error) {
console.log(error);
}
});