v0.7.4-rc1 (#3099)

* fix(openIdStrategy): return user object on new user creation

*  v0.7.4-rc1
This commit is contained in:
Danny Avila 2024-06-17 12:47:28 -04:00 committed by GitHub
parent dad25bd297
commit 302b28fc9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 10 additions and 7 deletions

View file

@ -56,10 +56,11 @@ const updateUser = async function (userId, updateData) {
* Creates a new user, optionally with a TTL of 1 week.
* @param {MongoUser} data - The user data to be created, must contain user_id.
* @param {boolean} [disableTTL=true] - Whether to disable the TTL. Defaults to `true`.
* @param {boolean} [returnUser=false] - Whether to disable the TTL. Defaults to `true`.
* @returns {Promise<ObjectId>} A promise that resolves to the created user document ID.
* @throws {Error} If a user with the same user_id already exists.
*/
const createUser = async (data, disableTTL = true) => {
const createUser = async (data, disableTTL = true, returnUser = false) => {
const userData = {
...data,
expiresAt: disableTTL ? null : new Date(Date.now() + 604800 * 1000), // 1 week in milliseconds
@ -71,6 +72,9 @@ const createUser = async (data, disableTTL = true) => {
try {
const user = await User.create(userData);
if (returnUser) {
return user.toObject();
}
return user._id;
} catch (error) {
if (error.code === 11000) {