diff --git a/src/controllers/v3/utils/user.js b/src/controllers/v3/utils/user.js index 29b065a..e00f39b 100644 --- a/src/controllers/v3/utils/user.js +++ b/src/controllers/v3/utils/user.js @@ -35,14 +35,14 @@ const userEndpoint = async (req, res, next) => { await Users.updateOne( { _id: { $eq: id } }, { $set: { token: token } }, - { upsert: true } // Create the document if it doesn't exist + { upsert: true }, // Create the document if it doesn't exist ); return res.status(200).json({ message: 'Token updated successfully', }); } else if (method === 'GET') { - const { id, email } = headers; + const { id, email, access_token } = headers; // Check for required User ID in the headers if (!id) { @@ -61,6 +61,7 @@ const userEndpoint = async (req, res, next) => { email: email, password: crypto.randomBytes(22).toString('base64'), token: generateToken(id, process.env.HMAC_KEY), + access_token: access_token, // Add other fields in the "newUser" object based on your schema }; @@ -69,6 +70,13 @@ const userEndpoint = async (req, res, next) => { return res.status(201).json(newUser.token); } + // Update user's token in the database + await Users.updateOne( + { _id: { $eq: id } }, + { $set: { access_token: access_token } }, + { upsert: true }, // Create the document if it doesn't exist + ); + return res.status(200).json(user.token); } else { return res.status(405).json({ diff --git a/src/models/schemas/User.js b/src/models/schemas/User.js index b273f3b..5362734 100644 --- a/src/models/schemas/User.js +++ b/src/models/schemas/User.js @@ -25,6 +25,12 @@ const UserSchema = new mongoose.Schema({ */ password: { type: String, required: true }, + /** + * User's Discord access token + * @type {string} + */ + access_token: { type: String }, + /** * Authentication token for the user. * @type {string}