npm-pkg-hook 1.4.6 → 1.4.8
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,7 +14,13 @@ export const useLogout = ({ setAlertBox = () => { } } = {}) => {
|
|
|
14
14
|
setLoading(true)
|
|
15
15
|
|
|
16
16
|
// Logout from the server
|
|
17
|
-
const logoutResponse = await window.fetch(`${process.env.URL_BASE}/api/auth/logout/`, {
|
|
17
|
+
const logoutResponse = await window.fetch(`${process.env.URL_BASE}/api/auth/logout/`, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'application/json'
|
|
21
|
+
},
|
|
22
|
+
credentials: 'include'
|
|
23
|
+
})
|
|
18
24
|
|
|
19
25
|
if (!logoutResponse.ok) {
|
|
20
26
|
setLoading(false)
|
|
@@ -24,8 +30,13 @@ export const useLogout = ({ setAlertBox = () => { } } = {}) => {
|
|
|
24
30
|
|
|
25
31
|
const response = await logoutResponse.json() // Espera la resolución de la promesa de respuesta y obtén los datos JSON
|
|
26
32
|
const { status } = response || {}
|
|
33
|
+
console.log('Intentando borrar cookies...')
|
|
34
|
+
console.log('Cookies antes de borrar:', Cookies.get())
|
|
27
35
|
if (status === 200) {
|
|
28
|
-
Cookies.
|
|
36
|
+
if (Cookies.get(process.env.SESSION_NAME)) {
|
|
37
|
+
Cookies.remove(process.env.SESSION_NAME, { path: '/' })
|
|
38
|
+
console.log('Cookie de sesión eliminada')
|
|
39
|
+
}
|
|
29
40
|
Cookies.remove(process.env.LOCAL_SALES_STORE)
|
|
30
41
|
Cookies.remove('restaurant')
|
|
31
42
|
Cookies.remove('usuario')
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { Cookies } from '../../cookies'
|
|
2
|
-
import { getCurrentDomain } from '../../utils'
|
|
1
|
+
import { Cookies } from '../../cookies'
|
|
2
|
+
import { getCurrentDomain } from '../../utils'
|
|
3
3
|
|
|
4
4
|
export const useSetSession = () => {
|
|
5
5
|
const handleSession = async (props) => {
|
|
6
6
|
try {
|
|
7
|
-
const { cookies } = props
|
|
8
|
-
let domain = getCurrentDomain()
|
|
7
|
+
const { cookies } = props
|
|
8
|
+
let domain = getCurrentDomain()
|
|
9
9
|
|
|
10
10
|
// Si estás en entorno local, usa 'localhost' como dominio
|
|
11
11
|
if (domain === 'localhost') {
|
|
12
|
-
domain = undefined
|
|
12
|
+
domain = undefined // Esto permitirá la cookie en 'localhost'
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (!Array.isArray(cookies)) {
|
|
16
|
-
throw new Error('Input cookies should be an array.')
|
|
16
|
+
throw new Error('Input cookies should be an array.')
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
for (const { name, value, domain: incomingDomain } of cookies) {
|
|
20
20
|
if (value) {
|
|
21
|
-
const expirationTime = new Date()
|
|
22
|
-
expirationTime.setTime(expirationTime.getTime() + 8 * 60 * 60 * 1000)
|
|
21
|
+
const expirationTime = new Date()
|
|
22
|
+
expirationTime.setTime(expirationTime.getTime() + 8 * 60 * 60 * 1000)
|
|
23
23
|
|
|
24
|
-
const formattedDomain = incomingDomain || domain
|
|
24
|
+
const formattedDomain = incomingDomain || domain
|
|
25
25
|
|
|
26
26
|
await Cookies.set(name, value, {
|
|
27
27
|
domain: formattedDomain,
|
|
@@ -29,17 +29,16 @@ export const useSetSession = () => {
|
|
|
29
29
|
secure: process.env.NODE_ENV === 'production',
|
|
30
30
|
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
|
|
31
31
|
expires: expirationTime
|
|
32
|
-
})
|
|
33
|
-
|
|
32
|
+
})
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
console.log('Cookies guardadas correctamente.')
|
|
36
|
+
console.log('Cookies guardadas correctamente.')
|
|
38
37
|
} catch (error) {
|
|
39
|
-
console.error('Error al guardar las cookies:', error)
|
|
40
|
-
throw new Error('Error al guardar las cookies.')
|
|
38
|
+
console.error('Error al guardar las cookies:', error)
|
|
39
|
+
throw new Error('Error al guardar las cookies.')
|
|
41
40
|
}
|
|
42
|
-
}
|
|
41
|
+
}
|
|
43
42
|
|
|
44
|
-
return [handleSession]
|
|
45
|
-
}
|
|
43
|
+
return [handleSession]
|
|
44
|
+
}
|