npm-pkg-hook 1.3.3 → 1.3.5
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
|
@@ -14,27 +14,36 @@ const ENCRYPTION_KEY = generateEncryptionKey(
|
|
|
14
14
|
const IV_LENGTH = 16 // Para AES, este siempre debe ser 16
|
|
15
15
|
|
|
16
16
|
export const encryptSession = (text) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
try {
|
|
18
|
+
const iv = crypto.randomBytes(IV_LENGTH)
|
|
19
|
+
const cipher = crypto.createCipheriv(
|
|
20
|
+
'aes-256-cbc',
|
|
21
|
+
Buffer.from(ENCRYPTION_KEY),
|
|
22
|
+
iv
|
|
23
|
+
)
|
|
24
|
+
let encrypted = cipher.update(text)
|
|
25
|
+
encrypted = Buffer.concat([encrypted, cipher.final()])
|
|
26
|
+
return iv.toString('hex') + ':' + encrypted.toString('hex')
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
export const decryptSession = (text) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
'
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
try {
|
|
34
|
+
if (!text) return
|
|
35
|
+
const textParts = text.split(':')
|
|
36
|
+
const iv = Buffer.from(textParts.shift(), 'hex')
|
|
37
|
+
const encryptedText = Buffer.from(textParts.join(':'), 'hex')
|
|
38
|
+
const decipher = crypto.createDecipheriv(
|
|
39
|
+
'aes-256-cbc',
|
|
40
|
+
Buffer.from(ENCRYPTION_KEY),
|
|
41
|
+
iv
|
|
42
|
+
)
|
|
43
|
+
let decrypted = decipher.update(encryptedText)
|
|
44
|
+
decrypted = Buffer.concat([decrypted, decipher.final()])
|
|
45
|
+
return decrypted.toString()
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
40
49
|
}
|
|
@@ -6,7 +6,7 @@ export const useGetStoreCookie = () => {
|
|
|
6
6
|
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
const getCookieValue = () => {
|
|
9
|
-
const cookieValue = Cookies.get(
|
|
9
|
+
const cookieValue = Cookies.get(process.env.SESSION_NAME);
|
|
10
10
|
console.log('Cookie Value:', cookieValue);
|
|
11
11
|
|
|
12
12
|
if (cookieValue) {
|
|
@@ -24,7 +24,7 @@ export const useLogout = ({ setAlertBox = () => { } } = {}) => {
|
|
|
24
24
|
localStorage.removeItem('latitude')
|
|
25
25
|
localStorage.removeItem('userlogin')
|
|
26
26
|
localStorage.removeItem('restaurant')
|
|
27
|
-
Cookies.remove(
|
|
27
|
+
Cookies.remove(process.env.SESSION_NAME)
|
|
28
28
|
Cookies.remove('app.cart.sales')
|
|
29
29
|
Cookies.remove('restaurant')
|
|
30
30
|
client?.clearStore()
|
|
@@ -2,26 +2,35 @@ import { Cookies } from '../../cookies';
|
|
|
2
2
|
import { getCurrentDomain } from '../../utils';
|
|
3
3
|
|
|
4
4
|
export const useSetSession = () => {
|
|
5
|
-
const domain = getCurrentDomain()
|
|
6
|
-
|
|
7
5
|
const handleSession = async (props) => {
|
|
8
6
|
try {
|
|
9
|
-
const {
|
|
10
|
-
|
|
7
|
+
const { cookies } = props;
|
|
8
|
+
let domain = getCurrentDomain();
|
|
9
|
+
|
|
10
|
+
// Si estás en entorno local, usa 'localhost' como dominio
|
|
11
|
+
if (domain === 'localhost') {
|
|
12
|
+
domain = undefined; // Esto permitirá la cookie en 'localhost'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!Array.isArray(cookies)) {
|
|
11
16
|
throw new Error('Input cookies should be an array.');
|
|
12
17
|
}
|
|
13
18
|
|
|
14
|
-
for (const { name, value } of
|
|
19
|
+
for (const { name, value, domain: incomingDomain } of cookies) {
|
|
15
20
|
if (value) {
|
|
16
21
|
const expirationTime = new Date();
|
|
17
|
-
expirationTime.setTime(expirationTime.getTime() + 8 * 60 * 60 * 1000)
|
|
22
|
+
expirationTime.setTime(expirationTime.getTime() + 8 * 60 * 60 * 1000);
|
|
23
|
+
|
|
24
|
+
const formattedDomain = incomingDomain || domain;
|
|
25
|
+
|
|
18
26
|
await Cookies.set(name, value, {
|
|
19
|
-
domain,
|
|
27
|
+
domain: formattedDomain,
|
|
20
28
|
path: '/',
|
|
21
|
-
secure:
|
|
22
|
-
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
|
|
29
|
+
secure: process.env.NODE_ENV === 'production',
|
|
30
|
+
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
|
|
23
31
|
expires: expirationTime
|
|
24
32
|
});
|
|
33
|
+
|
|
25
34
|
}
|
|
26
35
|
}
|
|
27
36
|
|