chore: remove jose as Bun now supports JWT 🍞 (#1167)

* chore: remove jose as Bun now supports JWT

* chore: npm audit
This commit is contained in:
Danny Avila 2023-11-12 00:44:46 -05:00 committed by GitHub
parent 9ca84edb9a
commit 5d95433c83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 68 deletions

View file

@ -1,4 +1,3 @@
const jose = require('jose');
const jwt = require('jsonwebtoken');
/**
@ -21,15 +20,6 @@ const jwt = require('jsonwebtoken');
* });
*/
async function signPayload({ payload, secret, expirationTime }) {
if (typeof Bun !== 'undefined') {
// this code will only run when the file is run with Bun
const encodedSecret = new TextEncoder().encode(secret);
return await new jose.SignJWT(payload)
.setProtectedHeader({ alg: 'HS256' })
.setExpirationTime(expirationTime + 's')
.sign(encodedSecret);
}
return jwt.sign(payload, secret, { expiresIn: expirationTime });
}