6 examples of 'jsonwebtoken expire' in JavaScript

Every line of 'jsonwebtoken expire' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
49function createRefreshToken(userId) {
50 return jwt.sign(
51 {
52 userId,
53 type: "refresh"
54 },
55 AUTH_SECRET,
56 {
57 expiresIn: REFRESH_TOKEN_EXPIRE_SECONDS,
58 issuer: JWT_ISSUER
59 }
60 );
61}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

10export function createToken(id, callback) {
11
12 const helper = utility.setSessionKey(id);
13
14 const token = jwt.sign({
15 _id: id,
16 _verify: helper.verify
17 }, config.secret, {
18 //noTimestamp: true
19 expiresIn: config.redis.token.time
20 });
21
22 callback(null, {
23 key: helper.key,
24 value: token
25 });
26}
26isExpired(offsetSeconds: number = 0): boolean {
27 const decoded = this.payload;
28 if (!decoded.hasOwnProperty('exp')) return null;
29
30 const date = new Date(0);
31 date.setUTCSeconds(decoded.exp);
32
33 return !(date.valueOf() > (new Date().valueOf() + (offsetSeconds * 1000)));
34}
54public get token() {
55 return jwt.sign({
56 id: this.id,
57 role: this.role
58 }, process.env.JWT_KEY);
59}
35public isExpired(): boolean {
36 return ((this.content.exp * 1000) < Date.now());
37}
28public isTokenExpired(token: string): boolean {
29 const decoded = this.decodeToken(token)
30
31 if (!decoded) {
32 return true
33 }
34
35 return Math.floor(Date.now() / 1000) >= decoded.exp
36}

Related snippets