npm-pkg-hook 1.2.8 → 1.3.0

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/package.json CHANGED
@@ -43,5 +43,5 @@
43
43
  "rm": "rm -rf node_modules package-lock.json && npm i",
44
44
  "test": "echo \"Error: no test specified\" && exit 1"
45
45
  },
46
- "version": "1.2.8"
46
+ "version": "1.3.0"
47
47
  }
@@ -1,21 +1,36 @@
1
- import { Cookies } from '../../cookies'
1
+ import { Cookies } from '../../cookies';
2
+ import { getCurrentDomain } from '../../utils';
2
3
 
3
4
  export const useSetSession = () => {
4
- const bookOptionsCookie = {
5
- RESTAURANT: 'restaurant'
6
- }
5
+ const domain = getCurrentDomain()
6
+
7
7
  const handleSession = async (props) => {
8
8
  try {
9
- const { cookie } = props
10
- for (const element of cookie) {
11
- const { name, value } = element
9
+ const { cookie } = props;
10
+ if (!Array.isArray(cookie)) {
11
+ throw new Error('Input cookies should be an array.');
12
+ }
13
+
14
+ for (const { name, value } of cookie) {
12
15
  if (value) {
13
- await Cookies.set(bookOptionsCookie[name], value)
16
+ const expirationTime = new Date();
17
+ expirationTime.setTime(expirationTime.getTime() + 8 * 60 * 60 * 1000)
18
+ await Cookies.set(name, value, {
19
+ domain,
20
+ path: '/',
21
+ secure: process.env.NODE_ENV === 'production',
22
+ sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax', // Configura 'none' en producción
23
+ expires: expirationTime
24
+ });
14
25
  }
15
26
  }
27
+
28
+ console.log('Cookies guardadas correctamente.');
16
29
  } catch (error) {
17
- throw new Error(error)
30
+ console.error('Error al guardar las cookies:', error);
31
+ throw new Error('Error al guardar las cookies.');
18
32
  }
19
- }
20
- return [handleSession]
21
- }
33
+ };
34
+
35
+ return [handleSession];
36
+ };
package/src/index.jsx CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './hooks/index'
2
2
  export * from './utils'
3
+ export * from './cookies'
3
4
  export * from './security'