mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
5e773ce950
Migrate from `settings-sharelatex` to `@overleaf/settings` GitOrigin-RevId: 9a298ba26382180c1351683c5fddc9004418c1e6
22 lines
538 B
JavaScript
22 lines
538 B
JavaScript
const { callbackify, promisify } = require('util')
|
|
const JWT = require('jsonwebtoken')
|
|
const Settings = require('@overleaf/settings')
|
|
|
|
const jwtSign = promisify(JWT.sign)
|
|
|
|
async function sign(payload, options = {}) {
|
|
const key = Settings.jwt.key
|
|
const algorithm = Settings.jwt.algorithm
|
|
if (!key || !algorithm) {
|
|
throw new Error('missing JWT configuration')
|
|
}
|
|
const token = await jwtSign(payload, key, { ...options, algorithm })
|
|
return token
|
|
}
|
|
|
|
module.exports = {
|
|
sign: callbackify(sign),
|
|
promises: {
|
|
sign,
|
|
},
|
|
}
|