@rpcbase/client 0.49.0 → 0.51.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.
@@ -0,0 +1,8 @@
1
+ /* @flow */
2
+
3
+
4
+ const AppProvider = () => {
5
+
6
+ }
7
+
8
+ export default AppProvider
@@ -6,6 +6,7 @@ import page from "page"
6
6
  import debug from "debug"
7
7
 
8
8
  import post from "../../helpers/post"
9
+ import {reconnect as rts_reconnect} from "../../rts"
9
10
 
10
11
  import {set_is_signed_in, set_uid} from "../index"
11
12
  import Footer from "../Footer"
@@ -53,6 +54,9 @@ const SignIn = ({
53
54
  log("redirect to:", redirect || onSuccessRedirect)
54
55
  set_uid(res.user_id)
55
56
  set_is_signed_in(true)
57
+
58
+ // we must now reconnect on the websocket as we now have a new cookie
59
+ rts_reconnect()
56
60
  onSuccess()
57
61
  if (redirect) {
58
62
  page(redirect)
@@ -7,6 +7,8 @@ import post from "../../helpers/post"
7
7
 
8
8
  import {set_is_signed_in, set_uid} from "../index"
9
9
 
10
+ // TODO: rts_disconnect
11
+ // TODO: clear cache + db
10
12
 
11
13
  const SignOut = ({
12
14
  onSuccess = () => null
@@ -21,6 +23,9 @@ const SignOut = ({
21
23
  set_uid(null)
22
24
  set_is_signed_in(false)
23
25
  localStorage.clear()
26
+
27
+ // TODO: clear DB
28
+
24
29
  setIsSignedOut(true)
25
30
  onSuccess()
26
31
  } else {
@@ -2,6 +2,8 @@
2
2
  import {useState} from "react"
3
3
  import page from "page"
4
4
 
5
+ import {reconnect as rts_reconnect} from "../../rts"
6
+
5
7
  import {set_is_signed_in, set_uid} from "../index"
6
8
  import post from "../../helpers/post"
7
9
  import Footer from "../Footer"
@@ -29,6 +31,9 @@ const SignUp = ({
29
31
  if (res.status === "ok") {
30
32
  set_uid(res.user_id)
31
33
  set_is_signed_in(true)
34
+
35
+ // we must now reconnect on the websocket as we now have a new cookie
36
+ rts_reconnect()
32
37
  onSuccess()
33
38
  page(onSuccessRedirect)
34
39
  } else if (res.status === "error") {
package/base_url.js ADDED
@@ -0,0 +1,16 @@
1
+ /* @flow */
2
+ import axios from "axios"
3
+
4
+ import {SERVER_PORT, HOSTNAME} from "env"
5
+
6
+ const protocol = (typeof window !== "undefined" && window?.location?.protocol) || "http:"
7
+
8
+ // there is no SERVER_PORT in production, as we use the default port and we are behind the gateway
9
+ // we assume we specify the port only when localhost or 127.0.0.1
10
+ const is_local = ["localhost", "127.0.0.1"].includes(HOSTNAME)
11
+
12
+ const BASE_URL = is_local ? `${protocol}//${HOSTNAME}:${SERVER_PORT}` : `https://${HOSTNAME}`
13
+
14
+ console.log("HOST", HOSTNAME, BASE_URL)
15
+
16
+ export default BASE_URL
package/helpers/post.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* @flow */
2
2
  import axios from "axios"
3
3
 
4
- import {BASE_URL} from "env"
4
+ import BASE_URL from "../base_url"
5
5
 
6
6
  const client = axios.create({
7
7
  withCredentials: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.49.0",
3
+ "version": "0.51.0",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 0"
6
6
  },
package/rpc_post.js CHANGED
@@ -7,7 +7,7 @@ import _set from "lodash/set"
7
7
  import get_txn_id from "@rpcbase/std/get_txn_id"
8
8
  import {add_local_txn} from "@rpcbase/client/rts"
9
9
 
10
- import {BASE_URL} from "env"
10
+ import BASE_URL from "./base_url"
11
11
 
12
12
  const client = axios.create({
13
13
  withCredentials: true,
package/rts/index.js CHANGED
@@ -5,7 +5,7 @@ import _get from "lodash/get"
5
5
  import _set from "lodash/set"
6
6
  import debug from "debug"
7
7
 
8
- import {BASE_URL} from "env"
8
+ import BASE_URL from "../base_url"
9
9
 
10
10
  import store from "./store"
11
11
  import getUseQuery from "./getUseQuery"