diff options
author | 2023-08-21 22:19:54 +0200 | |
---|---|---|
committer | 2023-08-21 22:23:57 +0200 | |
commit | 9fb0815b575cfc23ced6722b1a164328bd3cff1a (patch) | |
tree | 971a10bb74824d007cb74082a0a1d07dba3f30e2 /helpers/createJwt.js | |
parent | 4d28ac359b25d89d0dbb42dd3a6d32269eebc619 (diff) | |
download | auth-service-9fb0815b575cfc23ced6722b1a164328bd3cff1a.tar.gz auth-service-9fb0815b575cfc23ced6722b1a164328bd3cff1a.tar.bz2 auth-service-9fb0815b575cfc23ced6722b1a164328bd3cff1a.zip |
refactor, new routes
Diffstat (limited to 'helpers/createJwt.js')
-rw-r--r-- | helpers/createJwt.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/helpers/createJwt.js b/helpers/createJwt.js new file mode 100644 index 0000000..6c6983b --- /dev/null +++ b/helpers/createJwt.js @@ -0,0 +1,22 @@ +const fs = require('fs') +const jwt = require('jsonwebtoken') +const cert = fs.readFileSync(`${process.cwd()}/cert/jwt_256_rsa`) + +const createJwt = (user, sessionId) => jwt.sign({ + email: user.email, + verified: !!user.verify, + role: user.role, + sessionId, + }, + { + key: cert, + passphrase: process.env.RSA_PASS, + }, + { + expiresIn: parseInt(process.env.TOKEN_EXPIRES_IN), + issuer: 'pruss.it', + algorithm: 'RS256', + } +) + +module.exports = createJwt |