@knowlearning/agents 0.6.3 → 0.7.1
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/agents/browser/auth.js +2 -10
- package/agents/generic.js +3 -0
- package/browser.js +0 -1
- package/node.js +0 -1
- package/package.json +1 -1
package/agents/browser/auth.js
CHANGED
|
@@ -9,20 +9,12 @@ function login() {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function logout() {
|
|
12
|
-
|
|
12
|
+
// TODO: hit logout url to refresh cookie
|
|
13
13
|
window.location.reload()
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
async function getToken() {
|
|
17
|
-
|
|
18
|
-
if (token) return token
|
|
19
|
-
else {
|
|
20
|
-
const randArr = new Uint32Array(16)
|
|
21
|
-
crypto.getRandomValues(randArr)
|
|
22
|
-
const anonymousCredential = [...randArr].map(x => x.toString(16).padStart(2, '0')).join('')
|
|
23
|
-
localStorage.setItem('token', anonymousCredential)
|
|
24
|
-
return anonymousCredential
|
|
25
|
-
}
|
|
17
|
+
return localStorage.getItem('token')
|
|
26
18
|
}
|
|
27
19
|
|
|
28
20
|
export {
|
package/agents/generic.js
CHANGED
|
@@ -126,6 +126,9 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
|
|
|
126
126
|
if (message.error) console.warn('ERROR RESPONSE', message)
|
|
127
127
|
|
|
128
128
|
if (!authed) {
|
|
129
|
+
// TODO: credential refresh flow instead of forcing login
|
|
130
|
+
if (message.error) return login()
|
|
131
|
+
|
|
129
132
|
authed = true
|
|
130
133
|
if (!user) { // this is the first authed websocket connection
|
|
131
134
|
user = message.auth.user
|
package/browser.js
CHANGED
package/node.js
CHANGED