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 +1 -1
- package/src/hooks/useSetSession/index.js +27 -12
- package/src/index.jsx +1 -0
package/package.json
CHANGED
|
@@ -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
|
|
5
|
-
|
|
6
|
-
}
|
|
5
|
+
const domain = getCurrentDomain()
|
|
6
|
+
|
|
7
7
|
const handleSession = async (props) => {
|
|
8
8
|
try {
|
|
9
|
-
const { cookie } = props
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
+
console.error('Error al guardar las cookies:', error);
|
|
31
|
+
throw new Error('Error al guardar las cookies.');
|
|
18
32
|
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return [handleSession];
|
|
36
|
+
};
|
package/src/index.jsx
CHANGED