feat: bun api support 🥟 (#1021)

* chore: update bun lockfile

* feat: backend api bun support, jose used in bun runtime

* fix: add missing await for signPayload call
This commit is contained in:
Danny Avila 2023-10-07 11:16:06 -04:00 committed by GitHub
parent c0e2c58c03
commit e7ca40b5ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 128 additions and 29 deletions

View file

@ -1,6 +1,6 @@
const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const signPayload = require('../server/services/signPayload');
const userSchema = require('./schema/userSchema.js');
const { SESSION_EXPIRY } = process.env ?? {};
const expires = eval(SESSION_EXPIRY) ?? 1000 * 60 * 15;
@ -21,18 +21,17 @@ userSchema.methods.toJSON = function () {
};
};
userSchema.methods.generateToken = function () {
const token = jwt.sign(
{
userSchema.methods.generateToken = async function () {
return await signPayload({
payload: {
id: this._id,
username: this.username,
provider: this.provider,
email: this.email,
},
process.env.JWT_SECRET,
{ expiresIn: expires / 1000 },
);
return token;
secret: process.env.JWT_SECRET,
expirationTime: expires / 1000,
});
};
userSchema.methods.comparePassword = function (candidatePassword, callback) {