comty.js 0.60.4 → 0.60.6
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.
|
@@ -8,27 +8,25 @@ exports. default = async (data, callback) => {
|
|
|
8
8
|
return false
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
if (data.response
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
if (data.response) {
|
|
12
|
+
if (data.response.status === 401) {
|
|
13
|
+
// check if the server issue a refresh token on data
|
|
14
|
+
if (data.response.data.expired) {
|
|
15
|
+
try {
|
|
16
|
+
console.log(`Session expired, trying to regenerate...`)
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
await _refreshToken2.default.call(void 0, )
|
|
19
|
+
} catch (error) {
|
|
20
|
+
__comty_shared_state.eventBus.emit("session.invalid", error.message)
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
console.error(`Failed to regenerate token: ${error.message}`)
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
throw new Error(`Invalid or Expired session`)
|
|
25
|
+
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
return await callback()
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
if (data.response.status === 403) {
|
|
31
|
-
|
|
32
|
-
}
|
|
33
31
|
}
|
|
34
32
|
}
|
|
@@ -92,6 +92,29 @@ var _session = require('../session'); var _session2 = _interopRequireDefault(_se
|
|
|
92
92
|
return response
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Verifies the given token and returns the user data associated with it.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} [token] - The token to verify. If not provided, the stored token is used.
|
|
99
|
+
* @return {Promise<Object>} A Promise that resolves with the user data if the token is valid, or false if the token is invalid.
|
|
100
|
+
* @throws {Error} Throws an error if there was an issue with the request.
|
|
101
|
+
*/
|
|
102
|
+
static async authToken(token) {
|
|
103
|
+
if (!token) {
|
|
104
|
+
token = await Session.token
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const response = await _request2.default.call(void 0, {
|
|
108
|
+
method: "POST",
|
|
109
|
+
url: "/auth/token",
|
|
110
|
+
data: {
|
|
111
|
+
token: token
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
return response.data
|
|
116
|
+
}
|
|
117
|
+
|
|
95
118
|
/**
|
|
96
119
|
* Validates the existence of a username by making a GET request to the `/auth/{username}/exists` endpoint.
|
|
97
120
|
*
|
|
@@ -119,27 +119,6 @@ var _withStorage = require('../../helpers/withStorage'); var _withStorage2 = _in
|
|
|
119
119
|
return response.data
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
/**
|
|
123
|
-
* Retrieves the token validation data from the server.
|
|
124
|
-
*
|
|
125
|
-
* @return {Promise<Object>} The token validation data.
|
|
126
|
-
*/
|
|
127
|
-
static async authToken(token) {
|
|
128
|
-
if (!token) {
|
|
129
|
-
token = await Session.token
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const response = await _request2.default.call(void 0, {
|
|
133
|
-
method: "POST",
|
|
134
|
-
url: "/auth/token",
|
|
135
|
-
data: {
|
|
136
|
-
token: token
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
return response.data
|
|
141
|
-
}
|
|
142
|
-
|
|
143
122
|
/**
|
|
144
123
|
* Destroys the current session by deleting it from the server.
|
|
145
124
|
*
|