@goweekdays/core 2.11.8 → 2.11.9

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @goweekdays/core
2
2
 
3
+ ## 2.11.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 66abdad: Update dependencies
8
+
3
9
  ## 2.11.8
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ declare function useAuthService(): {
14
14
  sid: string;
15
15
  user: string;
16
16
  }>;
17
- logout: (sid: string) => Promise<string>;
17
+ logout: (user: string) => Promise<string>;
18
18
  };
19
19
 
20
20
  declare function useAuthController(): {
package/dist/index.js CHANGED
@@ -602,7 +602,6 @@ var v4_default = v4;
602
602
 
603
603
  // src/resources/auth/auth.service.ts
604
604
  function useAuthService() {
605
- const { setCache, delCache } = (0, import_utils2.useCache)("sessions");
606
605
  async function login({ email, password } = {}) {
607
606
  if (!email) {
608
607
  throw new import_utils2.BadRequestError("Email is required");
@@ -634,21 +633,19 @@ function useAuthService() {
634
633
  if (!isPasswordValid) {
635
634
  throw new import_utils2.BadRequestError("Invalid password");
636
635
  }
636
+ const { setCache } = (0, import_utils2.useCache)(`user:${_user._id?.toString()}`);
637
637
  const sid = v4_default();
638
638
  const cacheKey = `sid:${sid}`;
639
- setCache(cacheKey, _user, 14400).then(() => {
640
- console.log("Session ID cached successfully");
641
- }).catch((error) => {
642
- console.error("Error caching session ID:", error);
643
- });
639
+ await setCache(cacheKey, _user, 14400);
644
640
  return { sid, user: _user._id?.toString() ?? "" };
645
641
  }
646
- async function logout(sid) {
642
+ async function logout(user) {
643
+ const { delNamespace } = (0, import_utils2.useCache)(`user:${user}`);
647
644
  try {
648
- await delCache(`sid:${sid}`);
645
+ await delNamespace();
649
646
  return "Session deleted successfully";
650
647
  } catch (error) {
651
- throw new import_utils2.InternalServerError("Error deleting token");
648
+ throw new import_utils2.InternalServerError("Failed to delete session");
652
649
  }
653
650
  }
654
651
  return {
@@ -11176,13 +11173,13 @@ function useAuthController() {
11176
11173
  }
11177
11174
  }
11178
11175
  async function logout(req, res, next) {
11179
- const sid = req.headers["authorization"] ?? "";
11180
- if (!sid) {
11181
- next(new import_utils54.BadRequestError("Session ID is required"));
11176
+ const user = req.headers["user"] ?? "";
11177
+ if (!user) {
11178
+ next(new import_utils54.BadRequestError("Failed to identify user from request."));
11182
11179
  return;
11183
11180
  }
11184
11181
  try {
11185
- await useAuthService().logout(sid);
11182
+ await useAuthService().logout(user);
11186
11183
  res.json({ message: "Logged out successfully" });
11187
11184
  } catch (error) {
11188
11185
  if (error instanceof import_utils54.AppError) {