@goweekdays/core 2.11.8 → 2.11.10

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,17 @@
1
1
  # @goweekdays/core
2
2
 
3
+ ## 2.11.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 4c31cef: Update logout to use cookie and clear user sessions
8
+
9
+ ## 2.11.9
10
+
11
+ ### Patch Changes
12
+
13
+ - 66abdad: Update dependencies
14
+
3
15
  ## 2.11.8
4
16
 
5
17
  ### 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,22 @@ function useAuthService() {
634
633
  if (!isPasswordValid) {
635
634
  throw new import_utils2.BadRequestError("Invalid password");
636
635
  }
636
+ const { setCache, delNamespace } = (0, import_utils2.useCache)(
637
+ `user:${_user._id?.toString()}`
638
+ );
639
+ await delNamespace();
637
640
  const sid = v4_default();
638
641
  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
- });
642
+ await setCache(cacheKey, _user, 14400);
644
643
  return { sid, user: _user._id?.toString() ?? "" };
645
644
  }
646
- async function logout(sid) {
645
+ async function logout(user) {
646
+ const { delNamespace } = (0, import_utils2.useCache)(`user:${user}`);
647
647
  try {
648
- await delCache(`sid:${sid}`);
648
+ await delNamespace();
649
649
  return "Session deleted successfully";
650
650
  } catch (error) {
651
- throw new import_utils2.InternalServerError("Error deleting token");
651
+ throw new import_utils2.InternalServerError("Failed to delete session");
652
652
  }
653
653
  }
654
654
  return {
@@ -11176,13 +11176,13 @@ function useAuthController() {
11176
11176
  }
11177
11177
  }
11178
11178
  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"));
11179
+ const user = req.cookies.user;
11180
+ if (!user) {
11181
+ next(new import_utils54.BadRequestError("Failed to identify user from request."));
11182
11182
  return;
11183
11183
  }
11184
11184
  try {
11185
- await useAuthService().logout(sid);
11185
+ await useAuthService().logout(user);
11186
11186
  res.json({ message: "Logged out successfully" });
11187
11187
  } catch (error) {
11188
11188
  if (error instanceof import_utils54.AppError) {