Skip to content

Commit

Permalink
Regenerate access token
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackIQ committed Apr 21, 2023
1 parent 790114a commit 69332b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/controllers/user/user.controllers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { User } from "$app/models/index.js";
import { ray } from "$app/functions/index.js";

import md5 from "md5";

Expand Down Expand Up @@ -81,3 +82,23 @@ export const PASSWORD = async (req, res) => {
res.status(500).send({ message: error.message });
}
};

export const RE_GENERATE = async (req, res) => {
const { id } = req.params;

const data = {
access_token: ray.gen(25),
};

try {
const user = await User.findByIdAndUpdate(id, { $set: data });

if (user === null) {
return res.status(404).send({ message: "User not found" });
}

res.status(200).send({ message: "New access token generated" });
} catch (error) {
res.status(500).send({ message: error.message });
}
};
1 change: 1 addition & 0 deletions app/routes/user/user.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { User } from "$app/controllers/index.js";
const router = express.Router();

router.patch("/password/:id", User.PASSWORD);
router.get("/access/:id", User.RE_GENERATE);

router.get("/:id", User.SINGLE);
router.delete("/:id", User.DELETE);
Expand Down

0 comments on commit 69332b2

Please sign in to comment.