@ciscode/authentication-kit 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,4 +5,5 @@ export declare class UsersController {
5
5
  deleteUser(req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
6
6
  createUserInvitation(req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
7
7
  getAllUsers(req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
8
+ getMe(req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
8
9
  }
@@ -21,6 +21,7 @@ const user_model_1 = __importDefault(require("../models/user.model"));
21
21
  const nodemailer_1 = __importDefault(require("nodemailer"));
22
22
  const bcryptjs_1 = __importDefault(require("bcryptjs"));
23
23
  const node_crypto_1 = require("node:crypto");
24
+ const authenticate_guard_1 = require("../middleware/authenticate.guard");
24
25
  let UsersController = class UsersController {
25
26
  async createUser(req, res) {
26
27
  try {
@@ -204,6 +205,24 @@ Thank you!`
204
205
  return res.status(500).json({ message: 'Server error', error: error.message });
205
206
  }
206
207
  }
208
+ async getMe(req, res) {
209
+ var _a;
210
+ try {
211
+ const userId = (_a = req.user) === null || _a === void 0 ? void 0 : _a.id;
212
+ if (!userId) {
213
+ return res.status(401).json({ message: 'Unauthorized' });
214
+ }
215
+ const user = await user_model_1.default.findById(userId).select('-password -resetPasswordToken -resetPasswordExpires -refreshToken -__v');
216
+ if (!user) {
217
+ return res.status(404).json({ message: 'User not found.' });
218
+ }
219
+ return res.status(200).json(user);
220
+ }
221
+ catch (error) {
222
+ console.error('Error fetching current user:', error);
223
+ return res.status(500).json({ message: 'Server error', error: error.message });
224
+ }
225
+ }
207
226
  };
208
227
  exports.UsersController = UsersController;
209
228
  __decorate([
@@ -246,6 +265,15 @@ __decorate([
246
265
  __metadata("design:paramtypes", [Object, Object]),
247
266
  __metadata("design:returntype", Promise)
248
267
  ], UsersController.prototype, "getAllUsers", null);
268
+ __decorate([
269
+ (0, common_1.Get)('me'),
270
+ (0, common_1.UseGuards)(authenticate_guard_1.AuthenticateGuard),
271
+ __param(0, (0, common_1.Req)()),
272
+ __param(1, (0, common_1.Res)()),
273
+ __metadata("design:type", Function),
274
+ __metadata("design:paramtypes", [Object, Object]),
275
+ __metadata("design:returntype", Promise)
276
+ ], UsersController.prototype, "getMe", null);
249
277
  exports.UsersController = UsersController = __decorate([
250
278
  (0, common_1.Controller)('api/users')
251
279
  ], UsersController);
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/CISCODE-MA/AuthKit.git"
9
9
  },
10
- "version": "1.1.5",
10
+ "version": "1.1.6",
11
11
  "description": "A login library with local login, Microsoft Entra ID authentication, password reset, and roles/permissions.",
12
12
  "main": "dist/index.js",
13
13
  "types": "dist/index.d.ts",