@nitra/vite-boot 3.2.0 → 3.3.0
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 +1 -1
- package/src/token.js +14 -1
- package/src/user.js +1 -0
package/package.json
CHANGED
package/src/token.js
CHANGED
|
@@ -10,7 +10,7 @@ const allowedRoles = import.meta.env.VITE_HASURA_ROLE.split(',')
|
|
|
10
10
|
* та перенаправляємо на сторінку входу
|
|
11
11
|
*
|
|
12
12
|
* @param {string} token - JWT токен
|
|
13
|
-
* @returns {{result: string,
|
|
13
|
+
* @returns {{result: string, decoded?: {}}} - Повертає результат перевірки токена
|
|
14
14
|
*/
|
|
15
15
|
export function checkToken(token) {
|
|
16
16
|
const decoded = jwtDecode(token)
|
|
@@ -38,6 +38,12 @@ export function checkToken(token) {
|
|
|
38
38
|
* Токен з кукі
|
|
39
39
|
*/
|
|
40
40
|
export function getToken() {
|
|
41
|
+
// Якщо задано що токен беремо з localStorage
|
|
42
|
+
if (import.meta.env.VITE_TOKEN_STORAGE) {
|
|
43
|
+
return localStorage.getItem(import.meta.env.TOKEN_STORAGE)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// інакше з кукі
|
|
41
47
|
const cookieObj = new URLSearchParams(document.cookie.replaceAll('; ', '&')) // eslint-disable-line
|
|
42
48
|
const token = cookieObj.get('__session')
|
|
43
49
|
|
|
@@ -49,6 +55,13 @@ export function getToken() {
|
|
|
49
55
|
*/
|
|
50
56
|
export function cleanToken() {
|
|
51
57
|
unsetUser()
|
|
58
|
+
|
|
59
|
+
// Якщо задано що токен беремо з localStorage
|
|
60
|
+
// то й видаляємо з localStorage
|
|
61
|
+
if (import.meta.env.VITE_TOKEN_STORAGE) {
|
|
62
|
+
return localStorage.removeItem(import.meta.env.TOKEN_STORAGE)
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
document.cookie = `__session=; Max-Age=0; path=/; domain=${import.meta.env.VITE_DOMAIN}` // eslint-disable-line
|
|
53
66
|
}
|
|
54
67
|
|
package/src/user.js
CHANGED
|
@@ -9,6 +9,7 @@ export function unsetUser() {
|
|
|
9
9
|
export function setUser(u) {
|
|
10
10
|
user = u
|
|
11
11
|
|
|
12
|
+
user.login = u['https://hasura.io/jwt/claims']['x-hasura-user-id']
|
|
12
13
|
// Роль за умовчанням
|
|
13
14
|
const intersect = intersection(allowedRoles, u['https://hasura.io/jwt/claims']['x-hasura-allowed-roles'])
|
|
14
15
|
user.role = intersect[0]
|