mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
🪙 feat: automatically add start balance (#4486)
* automatically add start balance https://github.com/danny-avila/LibreChat/issues/2687 * chore: imports order in userMethods.js * Information about START_BALANCE has been added --------- Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
parent
493e64e6db
commit
d9ed161104
2 changed files with 13 additions and 0 deletions
|
@ -352,6 +352,7 @@ ILLEGAL_MODEL_REQ_SCORE=5
|
|||
#========================#
|
||||
|
||||
CHECK_BALANCE=false
|
||||
# START_BALANCE=20000 # note: the number of tokens that will be credited after registration.
|
||||
|
||||
#========================#
|
||||
# Registration and Login #
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
const bcrypt = require('bcryptjs');
|
||||
const signPayload = require('~/server/services/signPayload');
|
||||
const { isEnabled } = require('~/server/utils/handleText');
|
||||
const Balance = require('./Balance');
|
||||
const User = require('./User');
|
||||
|
||||
/**
|
||||
|
@ -71,6 +73,16 @@ const createUser = async (data, disableTTL = true, returnUser = false) => {
|
|||
}
|
||||
|
||||
const user = await User.create(userData);
|
||||
|
||||
if (isEnabled(process.env.CHECK_BALANCE) && process.env.START_BALANCE) {
|
||||
let incrementValue = parseInt(process.env.START_BALANCE);
|
||||
await Balance.findOneAndUpdate(
|
||||
{ user: user._id },
|
||||
{ $inc: { tokenCredits: incrementValue } },
|
||||
{ upsert: true, new: true },
|
||||
).lean();
|
||||
}
|
||||
|
||||
if (returnUser) {
|
||||
return user.toObject();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue