@nitra/vite-boot 3.3.0 → 3.3.2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitra/vite-boot",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
4
4
  "description": "Vite boot",
5
5
  "type": "module",
6
6
  "exports": {
package/src/login.js CHANGED
@@ -7,13 +7,13 @@ import { router } from '@nitra/vite-boot/router'
7
7
  /**
8
8
  * Автоматичний вхід користувача
9
9
  *
10
- * @param {{}} token
10
+ * @param {String} token
11
11
  */
12
12
  export async function autoLogin(token) {
13
13
  if (token) {
14
14
  const check = checkToken(token)
15
15
  if (check.result === 'ok') {
16
- await defaultLogin(check.decoded)
16
+ await defaultLogin(check.decoded, token)
17
17
  }
18
18
  }
19
19
  }
@@ -21,9 +21,15 @@ export async function autoLogin(token) {
21
21
  /**
22
22
  * Вхід аоб на попередню або на кореневу сторінку
23
23
  *
24
- * @param {{}} token
24
+ * @param {Object} decoded
25
+ * @param {String} raw? - необов'язково, але потрібно якщо використовується localStorage
25
26
  */
26
- export async function defaultLogin(decoded) {
27
+ export async function defaultLogin(decoded, raw = null) {
28
+ // Якщо задано що токен з localStorage
29
+ if (import.meta.env.VITE_TOKEN_STORAGE) {
30
+ return localStorage.setItem(import.meta.env.VITE_TOKEN_STORAGE, raw)
31
+ }
32
+
27
33
  setUser(decoded)
28
34
  const route = sessionStorage.getItem('url-before-logout') || '/'
29
35
  return router.push(route)
package/src/token.js CHANGED
@@ -101,7 +101,7 @@ export async function refreshToken() {
101
101
  // перезавантажуємо щоб він вступив в дію
102
102
  wsClient.restart()
103
103
  } else {
104
- await defaultLogin(check.decoded)
104
+ await defaultLogin(check.decoded, result.token)
105
105
  }
106
106
  }
107
107
  }