npm-pkg-hook 1.6.7 → 1.6.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 +3 -2
- package/src/hooks/getGlobalSession/index.js +2 -2
- package/src/hooks/index.js +2 -0
- package/src/hooks/isTokenExpired/index.js +17 -0
- package/src/hooks/useLogout/helpers/BroadcastChannel.js +30 -31
- package/src/hooks/useLogout/helpers/apiBaseUrl.js +8 -8
- package/src/hooks/useLogout/helpers/fetchData.js +23 -24
- package/src/hooks/useLogout/helpers/getCsrfToken.js +24 -24
- package/src/hooks/useLogout/helpers/index.js +51 -47
- package/src/hooks/useLogout/helpers/logger.js +36 -38
- package/src/hooks/useLogout/helpers/parseUrl.js +27 -27
- package/src/hooks/useLogout/index.js +17 -12
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"@babel/preset-env": "^7.19.1",
|
|
17
17
|
"@babel/preset-react": "^7.18.6",
|
|
18
18
|
"@babel/preset-typescript": "^7.18.6",
|
|
19
|
+
"@types/node": "^20.11.16",
|
|
19
20
|
"@types/react": "^18.0.20",
|
|
20
21
|
"@typescript-eslint/eslint-plugin": "5.29.0",
|
|
21
22
|
"@typescript-eslint/parser": "5.29.0",
|
|
@@ -43,5 +44,5 @@
|
|
|
43
44
|
"rm": "rm -rf node_modules package-lock.json && npm i",
|
|
44
45
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
45
46
|
},
|
|
46
|
-
"version": "1.6.
|
|
47
|
-
}
|
|
47
|
+
"version": "1.6.8"
|
|
48
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
2
|
|
|
3
|
-
function generateEncryptionKey(password, salt) {
|
|
3
|
+
function generateEncryptionKey (password, salt) {
|
|
4
4
|
return crypto
|
|
5
5
|
.pbkdf2Sync(password, salt, 100000, 32, 'sha256')
|
|
6
6
|
.toString('hex')
|
|
@@ -46,4 +46,4 @@ export const decryptSession = (text) => {
|
|
|
46
46
|
} catch (error) {
|
|
47
47
|
return null
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
package/src/hooks/index.js
CHANGED
|
@@ -7,7 +7,9 @@ export * from './useCatWithProduct'
|
|
|
7
7
|
export * from './useManageQueryParams'
|
|
8
8
|
export * from './useDeliveryTime'
|
|
9
9
|
export * from './statusOpenStores'
|
|
10
|
+
export * from './useLogout/helpers/BroadcastChannel'
|
|
10
11
|
export * from './newMessageSubscription'
|
|
12
|
+
export * from './isTokenExpired'
|
|
11
13
|
export * from './useCreateDeliveryTime'
|
|
12
14
|
export * from './addTenMinutes'
|
|
13
15
|
export * from './useCategoriesProduct'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifica si un token JWT ha expirado.
|
|
3
|
+
* @param {string} token El token JWT a verificar.
|
|
4
|
+
* @param {string} [expField='exp'] El nombre del campo que contiene la fecha de expiración en el token.
|
|
5
|
+
* @returns {boolean} True si el token ha expirado, false de lo contrario.
|
|
6
|
+
*/
|
|
7
|
+
export const isTokenExpired = (token, expField = 'exp') => {
|
|
8
|
+
try {
|
|
9
|
+
const [, payloadBase64] = token.split('.')
|
|
10
|
+
const decodedJson = Buffer.from(payloadBase64, 'base64').toString()
|
|
11
|
+
const decoded = JSON.parse(decodedJson)
|
|
12
|
+
const exp = decoded[expField] * 1000 // Convertir segundos a milisegundos
|
|
13
|
+
return Date.now() >= exp
|
|
14
|
+
} catch (error) {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
function BroadcastChannel(name =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
1
|
+
function BroadcastChannel (name = 'nextauth.message') {
|
|
2
|
+
return {
|
|
3
|
+
receive: function (onReceive) {
|
|
4
|
+
const handler = function (event) {
|
|
5
|
+
if (event.key !== name) return
|
|
6
|
+
const message = JSON.parse(event.newValue ?? '{}')
|
|
7
|
+
if (message?.event !== 'session' || !message?.data) return
|
|
8
|
+
onReceive(message)
|
|
9
|
+
}
|
|
10
|
+
window.addEventListener('storage', handler)
|
|
11
|
+
return function () {
|
|
12
|
+
window.removeEventListener('storage', handler)
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
post: function (message) {
|
|
16
|
+
if (typeof window === 'undefined') return
|
|
17
|
+
try {
|
|
18
|
+
localStorage.setItem(
|
|
19
|
+
name,
|
|
20
|
+
JSON.stringify({ ...message, timestamp: Date.now() })
|
|
21
|
+
)
|
|
22
|
+
} catch {
|
|
23
|
+
// The localStorage API isn't always available.
|
|
24
|
+
// It won't work in private mode prior to Safari 11 for example.
|
|
25
|
+
// Notifications are simply dropped if an error is encountered.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { BroadcastChannel }
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export function apiBaseUrl(__NEXTAUTH) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export function apiBaseUrl (__NEXTAUTH) {
|
|
2
|
+
if (typeof window === 'undefined') {
|
|
3
|
+
// Return absolute path when called server side
|
|
4
|
+
return `${__NEXTAUTH.baseUrlServer}${__NEXTAUTH.basePathServer}`
|
|
5
|
+
}
|
|
6
|
+
// Return relative path when called client side
|
|
7
|
+
return __NEXTAUTH.basePath
|
|
8
|
+
}
|
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
import { apiBaseUrl } from
|
|
1
|
+
import { apiBaseUrl } from './apiBaseUrl'
|
|
2
2
|
|
|
3
|
-
async function fetchData(path, __NEXTAUTH, logger, { ctx, req } = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
if (req?.body) {
|
|
14
|
-
options.body = JSON.stringify(req.body);
|
|
15
|
-
options.method = "POST";
|
|
3
|
+
async function fetchData (path, __NEXTAUTH, logger, { ctx, req } = {}) {
|
|
4
|
+
const url = `${apiBaseUrl(__NEXTAUTH)}/${path}`
|
|
5
|
+
try {
|
|
6
|
+
const options = {
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
...(req?.headers?.cookie ? { cookie: req.headers.cookie } : {})
|
|
16
10
|
}
|
|
11
|
+
}
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return Object.keys(data).length > 0 ? data : null; // Return null if data is empty
|
|
22
|
-
} catch (error) {
|
|
23
|
-
logger.error("CLIENT_FETCH_ERROR", { error, url });
|
|
24
|
-
return null;
|
|
13
|
+
if (req?.body) {
|
|
14
|
+
options.body = JSON.stringify(req.body)
|
|
15
|
+
options.method = 'POST'
|
|
25
16
|
}
|
|
17
|
+
|
|
18
|
+
const res = await fetch(url, options)
|
|
19
|
+
const data = await res.json()
|
|
20
|
+
if (!res.ok) throw data
|
|
21
|
+
return Object.keys(data).length > 0 ? data : null // Return null if data is empty
|
|
22
|
+
} catch (error) {
|
|
23
|
+
logger.error('CLIENT_FETCH_ERROR', { error, url })
|
|
24
|
+
return null
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { fetchData }
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { fetchData } from
|
|
2
|
-
import _logger, { proxyLogger } from
|
|
3
|
-
import { parseUrl } from
|
|
1
|
+
import { fetchData } from './fetchData'
|
|
2
|
+
import _logger, { proxyLogger } from './logger'
|
|
3
|
+
import { parseUrl } from './parseUrl'
|
|
4
4
|
|
|
5
5
|
const __NEXTAUTH = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
baseUrl: parseUrl(process.env.NEXTAUTH_URL || process.env.VERCEL_URL).origin,
|
|
7
|
+
basePath: parseUrl(process.env.NEXTAUTH_URL).path,
|
|
8
|
+
baseUrlServer: parseUrl(
|
|
9
|
+
process.env.NEXTAUTH_URL_INTERNAL ||
|
|
10
10
|
process.env.NEXTAUTH_URL ||
|
|
11
11
|
process.env.VERCEL_URL
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
).origin,
|
|
13
|
+
basePathServer: parseUrl(
|
|
14
|
+
process.env.NEXTAUTH_URL_INTERNAL || process.env.NEXTAUTH_URL
|
|
15
|
+
).path,
|
|
16
|
+
_lastSync: 0,
|
|
17
|
+
_session: undefined,
|
|
18
|
+
_getSession: () => {}
|
|
19
|
+
}
|
|
20
20
|
const logger = proxyLogger(_logger, __NEXTAUTH.basePath)
|
|
21
21
|
|
|
22
|
-
export async function getCsrfToken(params) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
export async function getCsrfToken (params) {
|
|
23
|
+
const response = await fetchData(
|
|
24
|
+
'csrf',
|
|
25
|
+
__NEXTAUTH,
|
|
26
|
+
logger,
|
|
27
|
+
params
|
|
28
|
+
)
|
|
29
|
+
return response?.csrfToken
|
|
30
|
+
}
|
|
@@ -1,54 +1,58 @@
|
|
|
1
|
-
import { apiBaseUrl } from
|
|
2
|
-
import { getCsrfToken } from
|
|
3
|
-
import { parseUrl } from
|
|
4
|
-
import { BroadcastChannel } from
|
|
1
|
+
import { apiBaseUrl } from './apiBaseUrl'
|
|
2
|
+
import { getCsrfToken } from './getCsrfToken'
|
|
3
|
+
import { parseUrl } from './parseUrl'
|
|
4
|
+
import { BroadcastChannel } from './BroadcastChannel'
|
|
5
5
|
|
|
6
6
|
const broadcast = BroadcastChannel()
|
|
7
7
|
|
|
8
8
|
export const __NEXTAUTH = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
baseUrl: parseUrl(process.env.NEXTAUTH_URL || process.env.VERCEL_URL).origin,
|
|
10
|
+
basePath: parseUrl(process.env.NEXTAUTH_URL).path,
|
|
11
|
+
baseUrlServer: parseUrl(
|
|
12
|
+
process.env.NEXTAUTH_URL_INTERNAL ||
|
|
13
|
+
process.env.NEXTAUTH_URL ||
|
|
14
|
+
process.env.VERCEL_URL
|
|
15
|
+
).origin,
|
|
16
|
+
basePathServer: parseUrl(
|
|
17
|
+
process.env.NEXTAUTH_URL_INTERNAL || process.env.NEXTAUTH_URL
|
|
18
|
+
).path,
|
|
19
|
+
_lastSync: 0,
|
|
20
|
+
_session: undefined,
|
|
21
|
+
_getSession: () => {}
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
export async function signOutAuth (options) {
|
|
25
|
+
const { callbackUrl = window.location.href, reload = true } = options ?? {}
|
|
26
|
+
console.log('🚀 ~ signOutAuth ~ options:', options)
|
|
27
|
+
const baseUrl = apiBaseUrl(__NEXTAUTH)
|
|
28
|
+
const fetchOptions = {
|
|
29
|
+
method: 'post',
|
|
30
|
+
headers: {
|
|
31
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
32
|
+
},
|
|
33
|
+
// @ts-expect-error
|
|
34
|
+
body: new URLSearchParams({
|
|
35
|
+
csrfToken: await getCsrfToken(),
|
|
36
|
+
callbackUrl,
|
|
37
|
+
json: true
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
const res = await fetch(`${baseUrl}/signout`, fetchOptions)
|
|
41
|
+
const data = await res.json()
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const url = data.url ?? callbackUrl
|
|
46
|
-
window.location.href = url
|
|
47
|
-
// If url contains a hash, the browser does not reload the page. We reload manually
|
|
48
|
-
if (url.includes("#")) window.location.reload()
|
|
49
|
-
// @ts-expect-error
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
await __NEXTAUTH._getSession({ event: "storage" })
|
|
43
|
+
broadcast.post({ event: 'session', data: { trigger: 'signout' } })
|
|
44
|
+
if (!reload) {
|
|
45
|
+
await __NEXTAUTH._getSession({ event: 'storage' })
|
|
53
46
|
return data
|
|
54
|
-
}
|
|
47
|
+
}
|
|
48
|
+
if (options?.redirect ?? true) {
|
|
49
|
+
const url = data.url ?? callbackUrl
|
|
50
|
+
window.location.href = url
|
|
51
|
+
// If url contains a hash, the browser does not reload the page. We reload manually
|
|
52
|
+
if (url.includes('#') && !reload) window.location.reload()
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
await __NEXTAUTH._getSession({ event: 'storage' })
|
|
57
|
+
return data
|
|
58
|
+
}
|
|
@@ -1,72 +1,70 @@
|
|
|
1
|
-
function formatError(o) {
|
|
1
|
+
function formatError (o) {
|
|
2
2
|
if (hasErrorProperty(o)) {
|
|
3
|
-
o.error = formatError(o.error)
|
|
4
|
-
o.message = o.message ?? o.error.message
|
|
3
|
+
o.error = formatError(o.error)
|
|
4
|
+
o.message = o.message ?? o.error.message
|
|
5
5
|
}
|
|
6
|
-
return o
|
|
6
|
+
return o
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function hasErrorProperty(x) {
|
|
10
|
-
return !!(x?.error)
|
|
9
|
+
function hasErrorProperty (x) {
|
|
10
|
+
return !!(x?.error)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const _logger = {
|
|
14
|
-
error(code, metadata) {
|
|
15
|
-
metadata = formatError(metadata)
|
|
14
|
+
error (code, metadata) {
|
|
15
|
+
metadata = formatError(metadata)
|
|
16
16
|
console.error(
|
|
17
17
|
`[next-auth][error][${code}]`,
|
|
18
18
|
`\nhttps://next-auth.js.org/errors#${code.toLowerCase()}`,
|
|
19
19
|
metadata.message,
|
|
20
20
|
metadata
|
|
21
|
-
)
|
|
21
|
+
)
|
|
22
22
|
},
|
|
23
|
-
warn(code) {
|
|
23
|
+
warn (code) {
|
|
24
24
|
console.warn(
|
|
25
25
|
`[next-auth][warn][${code}]`,
|
|
26
26
|
`\nhttps://next-auth.js.org/warnings#${code.toLowerCase()}`
|
|
27
|
-
)
|
|
27
|
+
)
|
|
28
28
|
},
|
|
29
|
-
debug(code, metadata) {
|
|
30
|
-
console.log(`[next-auth][debug][${code}]`, metadata)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
29
|
+
debug (code, metadata) {
|
|
30
|
+
console.log(`[next-auth][debug][${code}]`, metadata)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
34
33
|
|
|
35
|
-
export function setLogger(newLogger = {}, debug) {
|
|
36
|
-
if (!debug) _logger.debug = () => {}
|
|
34
|
+
export function setLogger (newLogger = {}, debug) {
|
|
35
|
+
if (!debug) _logger.debug = () => {}
|
|
37
36
|
|
|
38
|
-
if (newLogger.error) _logger.error = newLogger.error
|
|
39
|
-
if (newLogger.warn) _logger.warn = newLogger.warn
|
|
40
|
-
if (newLogger.debug) _logger.debug = newLogger.debug
|
|
37
|
+
if (newLogger.error) _logger.error = newLogger.error
|
|
38
|
+
if (newLogger.warn) _logger.warn = newLogger.warn
|
|
39
|
+
if (newLogger.debug) _logger.debug = newLogger.debug
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
export function proxyLogger(logger = _logger, basePath) {
|
|
42
|
+
export function proxyLogger (logger = _logger, basePath) {
|
|
44
43
|
try {
|
|
45
|
-
if (typeof window ===
|
|
46
|
-
return logger
|
|
44
|
+
if (typeof window === 'undefined') {
|
|
45
|
+
return logger
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
const clientLogger = {}
|
|
48
|
+
const clientLogger = {}
|
|
50
49
|
for (const level in logger) {
|
|
51
50
|
clientLogger[level] = (code, metadata) => {
|
|
52
|
-
_logger[level](code, metadata)
|
|
51
|
+
_logger[level](code, metadata)
|
|
53
52
|
|
|
54
|
-
if (level ===
|
|
55
|
-
metadata = formatError(metadata)
|
|
53
|
+
if (level === 'error') {
|
|
54
|
+
metadata = formatError(metadata)
|
|
56
55
|
}
|
|
57
|
-
metadata.client = true
|
|
58
|
-
const url = `${basePath}/_log
|
|
59
|
-
const body = new URLSearchParams({ level, code, ...metadata })
|
|
56
|
+
metadata.client = true
|
|
57
|
+
const url = `${basePath}/_log`
|
|
58
|
+
const body = new URLSearchParams({ level, code, ...metadata })
|
|
60
59
|
if (navigator.sendBeacon) {
|
|
61
|
-
return navigator.sendBeacon(url, body)
|
|
60
|
+
return navigator.sendBeacon(url, body)
|
|
62
61
|
}
|
|
63
|
-
return fetch(url, { method:
|
|
64
|
-
}
|
|
62
|
+
return fetch(url, { method: 'POST', body, keepalive: true })
|
|
63
|
+
}
|
|
65
64
|
}
|
|
66
|
-
return clientLogger
|
|
65
|
+
return clientLogger
|
|
67
66
|
} catch {
|
|
68
|
-
return _logger
|
|
67
|
+
return _logger
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
|
-
export { _logger as default }
|
|
72
|
-
|
|
70
|
+
export { _logger as default }
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
/** Interface for the internal URL structure */
|
|
2
2
|
const InternalUrl = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
origin: 'http://localhost:3000',
|
|
4
|
+
host: 'localhost:3000',
|
|
5
|
+
path: '/api/auth',
|
|
6
|
+
base: 'http://localhost:3000/api/auth',
|
|
7
|
+
toString: function () {
|
|
8
|
+
return this.base
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
/** Function to parse a URL-like object for server-side requests/redirects */
|
|
13
|
+
function parseUrl (url) {
|
|
14
|
+
const defaultUrl = new URL('http://localhost:3000/api/auth')
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (url && !url.startsWith('http')) {
|
|
17
|
+
url = `https://${url}`
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const _url = new URL(url || defaultUrl)
|
|
21
|
+
const path = (_url.pathname === '/' ? defaultUrl.pathname : _url.pathname).replace(/\/$/, '')
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const base = `${_url.origin}${path}`
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
25
|
+
return {
|
|
26
|
+
origin: _url.origin,
|
|
27
|
+
host: _url.host,
|
|
28
|
+
path,
|
|
29
|
+
base,
|
|
30
|
+
toString: function () {
|
|
31
|
+
return base
|
|
32
|
+
}
|
|
34
33
|
}
|
|
34
|
+
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
export { InternalUrl, parseUrl }
|
|
@@ -5,7 +5,11 @@ import { signOutAuth } from './helpers'
|
|
|
5
5
|
import { getCurrentDomain } from '../../utils'
|
|
6
6
|
export { signOutAuth } from './helpers'
|
|
7
7
|
|
|
8
|
-
export const useLogout = ({
|
|
8
|
+
export const useLogout = ({
|
|
9
|
+
setAlertBox = ({
|
|
10
|
+
message
|
|
11
|
+
}) => { return { message } }
|
|
12
|
+
} = {}) => {
|
|
9
13
|
const [loading, setLoading] = useState(false)
|
|
10
14
|
const [error, setError] = useState(false)
|
|
11
15
|
const client = useApolloClient()
|
|
@@ -32,17 +36,19 @@ export const useLogout = ({ setAlertBox = () => {} } = {}) => {
|
|
|
32
36
|
throw new Error('Error al eliminar la cookie. ')
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
const deleteCookie = async () => {
|
|
40
|
+
await eliminarCookie(process.env.SESSION_NAME)
|
|
41
|
+
await eliminarCookie(process.env.LOCAL_SALES_STORE)
|
|
42
|
+
await eliminarCookie('restaurant')
|
|
43
|
+
await eliminarCookie('usuario')
|
|
44
|
+
await eliminarCookie('session')
|
|
45
|
+
}
|
|
46
|
+
const onClickLogout = async ({ redirect = true } = { redirect: true }) => {
|
|
47
|
+
console.log(redirect)
|
|
37
48
|
try {
|
|
49
|
+
if (!redirect) return await deleteCookie()
|
|
38
50
|
setLoading(true)
|
|
39
|
-
|
|
40
|
-
await eliminarCookie(process.env.SESSION_NAME)
|
|
41
|
-
await eliminarCookie(process.env.LOCAL_SALES_STORE)
|
|
42
|
-
await eliminarCookie('restaurant')
|
|
43
|
-
await eliminarCookie('usuario')
|
|
44
|
-
await eliminarCookie('session')
|
|
45
|
-
|
|
51
|
+
await deleteCookie()
|
|
46
52
|
// Logout from the server
|
|
47
53
|
const logoutResponse = await fetch(`${process.env.URL_BASE}/api/auth/logout/`, {
|
|
48
54
|
method: 'POST',
|
|
@@ -57,8 +63,7 @@ export const useLogout = ({ setAlertBox = () => {} } = {}) => {
|
|
|
57
63
|
return
|
|
58
64
|
}
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
const { status } = response || {}
|
|
66
|
+
await logoutResponse.json()
|
|
62
67
|
console.log('Intentando borrar cookies...')
|
|
63
68
|
|
|
64
69
|
// Eliminar la cookie process.env.SESSION_NAME
|