@rpcbase/client 0.98.0 → 0.100.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/auth/index.js +3 -1
- package/package.json +1 -1
- package/storage/index.native.js +15 -8
- package/storage/index.web.js +14 -74
package/auth/index.js
CHANGED
|
@@ -3,11 +3,13 @@ import debug from "debug"
|
|
|
3
3
|
import {Platform} from "react-native"
|
|
4
4
|
import isHexadecimal from "validator/lib/isHexadecimal"
|
|
5
5
|
|
|
6
|
+
import storage from "../storage"
|
|
6
7
|
import {disconnect as rts_disconnect} from "../rts"
|
|
7
8
|
import post from "../helpers/post"
|
|
8
9
|
|
|
9
10
|
import redirect_sign_in from "./helpers/redirect_sign_in"
|
|
10
11
|
|
|
12
|
+
|
|
11
13
|
const LAST_TENANT_KEY = "rb.last_tenant_id"
|
|
12
14
|
const uid_storage_key = (tenant_id) => `rb.${tenant_id}.user_id`
|
|
13
15
|
|
|
@@ -118,7 +120,7 @@ export const set_uid = (val) => {
|
|
|
118
120
|
export const get_tenant_id = () => __tenant_id
|
|
119
121
|
export const set_tenant_id = (val) => {
|
|
120
122
|
__tenant_id = val
|
|
121
|
-
|
|
123
|
+
storage.setItem(LAST_TENANT_KEY, val)
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
export const set_is_signed_in = (val) => __is_authenticated = val
|
package/package.json
CHANGED
package/storage/index.native.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
import
|
|
2
|
+
import {MMKV} from "react-native-mmkv"
|
|
3
|
+
|
|
4
|
+
// TODO: add encryption key
|
|
5
|
+
// https://github.com/mrousavy/react-native-mmkv#customize
|
|
6
|
+
const mmkv = new MMKV
|
|
3
7
|
|
|
4
8
|
const getStorage = () => {
|
|
5
9
|
const storage = {
|
|
6
|
-
|
|
10
|
+
getItem: (key) => {
|
|
7
11
|
try {
|
|
8
|
-
const res =
|
|
12
|
+
const res = mmkv.getString(key)
|
|
13
|
+
if (!res) return
|
|
9
14
|
const val = JSON.parse(res)
|
|
10
15
|
if (val) return val
|
|
11
16
|
} catch (error) {
|
|
12
17
|
// There was an error on the native side
|
|
18
|
+
console.log("storage.getItem error:", error)
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
setItem: (key, value) => {
|
|
22
|
+
if (value === null || typeof value === "undefined") {
|
|
23
|
+
mmkv.delete(key)
|
|
24
|
+
return
|
|
25
|
+
} else {
|
|
26
|
+
mmkv.set(key, JSON.stringify(value))
|
|
20
27
|
}
|
|
21
28
|
}
|
|
22
29
|
}
|
package/storage/index.web.js
CHANGED
|
@@ -1,81 +1,21 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
-
const storeName = "store"
|
|
3
|
-
const version = 1
|
|
4
|
-
|
|
5
|
-
const getStorage = (
|
|
6
|
-
dbName = "rb-store"
|
|
7
|
-
) => {
|
|
8
|
-
let __db
|
|
9
|
-
|
|
10
|
-
const openRequest = indexedDB.open(dbName, version)
|
|
11
|
-
|
|
12
|
-
// Handle the creation or upgrade of the database
|
|
13
|
-
openRequest.onupgradeneeded = (event) => {
|
|
14
|
-
const db = event.target.result
|
|
15
|
-
if (!db.objectStoreNames.contains(storeName)) {
|
|
16
|
-
db.createObjectStore(storeName, { keyPath: "key" })
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Handle errors when opening the database
|
|
21
|
-
openRequest.onerror = (event) => {
|
|
22
|
-
console.error("Error opening database:", event.target.errorCode)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
openRequest.onsuccess = (event) => {
|
|
26
|
-
const db = event.target.result
|
|
27
|
-
__db = db
|
|
28
|
-
}
|
|
29
|
-
|
|
30
2
|
|
|
3
|
+
const getStorage = () => {
|
|
31
4
|
const storage = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
request.onerror = (event) => {
|
|
43
|
-
console.error("Error reading data:", event.target)
|
|
44
|
-
reject()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}),
|
|
48
|
-
set: (key, obj) => new Promise((resolve, reject) => {
|
|
49
|
-
|
|
50
|
-
const transaction = __db.transaction([storeName], "readwrite")
|
|
51
|
-
const objectStore = transaction.objectStore(storeName)
|
|
52
|
-
const request = objectStore.put({obj, key})
|
|
53
|
-
|
|
54
|
-
request.onsuccess = (event) => {
|
|
55
|
-
// console.log("Data written successfully:", event.target.result)
|
|
56
|
-
resolve()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
request.onerror = (event) => {
|
|
60
|
-
// console.error("Error writing data:", event.target.errorCode)
|
|
61
|
-
console.log("ERRR", event.target)
|
|
62
|
-
reject()
|
|
63
|
-
}
|
|
64
|
-
}),
|
|
65
|
-
delete: (key) => new Promise((resolve, reject) => {
|
|
66
|
-
const transaction = __db.transaction([storeName], "readwrite")
|
|
67
|
-
const objectStore = transaction.objectStore(storeName)
|
|
68
|
-
const request = objectStore.delete(key)
|
|
69
|
-
|
|
70
|
-
request.onsuccess = (event) => {
|
|
71
|
-
resolve()
|
|
5
|
+
getItem: (key) => {
|
|
6
|
+
try {
|
|
7
|
+
const res = localStorage.getItem(key)
|
|
8
|
+
if (!res) return
|
|
9
|
+
const val = JSON.parse(res)
|
|
10
|
+
return val
|
|
11
|
+
} catch (error) {
|
|
12
|
+
// There was an error on the native side
|
|
13
|
+
console.log(error)
|
|
72
14
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
}),
|
|
15
|
+
},
|
|
16
|
+
setItem: (key, value) => {
|
|
17
|
+
localStorage.setItem(key, JSON.stringify(value))
|
|
18
|
+
}
|
|
79
19
|
}
|
|
80
20
|
|
|
81
21
|
return storage
|