@knowlearning/agents 0.9.12 → 0.9.14

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.
@@ -1,24 +1,34 @@
1
1
  const AUTH_HOST = 'https://auth.knowlearning.systems'
2
2
 
3
+ // auth token info is sent with pathnames of form /auth/VERIFICATION_STATE/PROVIDER_TOKEN
4
+ if (window.location.pathname.startsWith('/auth/')) {
5
+ const state_token = window.location.pathname.slice(6)
6
+ const [state] = state_token.split('/', 1)
7
+ const origin = window.localStorage.getItem(state)
8
+ if (origin) {
9
+ const token = state_token.slice(state.length + 1)
10
+ window.localStorage.setItem('token', token)
11
+ window.location.href = origin
12
+ }
13
+ }
14
+
3
15
  function login() {
4
16
  const provider = 'google'
5
17
  const state = Math.random().toString(36).substring(2)
6
- console.log('SETTING localStorage "state"', state, window.location)
7
- localStorage.setItem('state', state)
18
+ window.localStorage.setItem(state, window.location.href)
8
19
 
9
20
  window.location.href = `${AUTH_HOST}/${provider}/${state}/${encodeURIComponent(window.location.href)}`
10
21
  }
11
22
 
12
23
  function logout() {
13
24
  // Doing this will establish a new anonymous session
14
- localStorage.setItem('token', Math.random().toString(36).substring(2))
25
+ window.localStorage.setItem('token', Math.random().toString(36).substring(2))
15
26
  window.location.reload()
16
27
  }
17
28
 
18
29
  async function getToken() {
19
- // Browser tokens are 1 time use
20
30
  const token = localStorage.getItem('token')
21
- localStorage.removeItem('token')
31
+ window.localStorage.removeItem('token')
22
32
  return token
23
33
  }
24
34
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.9.12",
3
+ "version": "0.9.14",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",