Skip to content

Commit

Permalink
Added a way to store access_token
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrea committed Jan 5, 2024
1 parent 45c1ff8 commit bc10f32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/controllers/v3/utils/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
};

Expand All @@ -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({
Expand Down
6 changes: 6 additions & 0 deletions src/models/schemas/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit bc10f32

Please sign in to comment.