@rpcbase/client 0.172.0 → 0.174.0-pagerouterauth.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.
@@ -1,8 +1,9 @@
1
1
  /* @flow */
2
2
  import "./debug"
3
-
3
+ import {useEffect} from "react"
4
4
  import {PostHogProvider} from "posthog-js/react"
5
5
 
6
+ import page from "../page"
6
7
  import {HashStateProvider} from "../hashState"
7
8
 
8
9
  import AnalyticsContainer from "./AnalyticsContainer"
@@ -11,6 +12,7 @@ import AnalyticsContainer from "./AnalyticsContainer"
11
12
  import {flagValues} from "config/flags"
12
13
 
13
14
  import {POSTHOG_KEY} from "env"
15
+ import { useAuthRouter } from "../auth/useAuthRouter"
14
16
 
15
17
 
16
18
  const PostHogWrapper = ({children, ...props}) => {
@@ -43,13 +45,18 @@ const PostHogWrapper = ({children, ...props}) => {
43
45
  }
44
46
  }
45
47
 
46
-
47
48
  const AppProvider = ({children, ...props}) => {
48
49
 
50
+ const {authComponent} = useAuthRouter()
51
+
52
+ useEffect(() => {
53
+ page()
54
+ }, [])
55
+
49
56
  return (
50
57
  <PostHogWrapper>
51
58
  <HashStateProvider>
52
- {children}
59
+ {authComponent || children}
53
60
  </HashStateProvider>
54
61
  </PostHogWrapper>
55
62
  )
@@ -23,7 +23,7 @@ const hasMultiAccounts = authConfig.has_multi_accounts
23
23
  const SignOut = ({
24
24
  logo,
25
25
  name,
26
- onSuccess = () => null
26
+ onSignOutSuccess = () => null
27
27
  }) => {
28
28
 
29
29
  const [isSignedOut, setIsSignedOut] = useState(false)
@@ -51,7 +51,7 @@ const SignOut = ({
51
51
  if (res.status === "ok") {
52
52
  sign_out()
53
53
  setIsSignedOut(true)
54
- onSuccess()
54
+ onSignOutSuccess()
55
55
  } else {
56
56
  throw new Error("unable to sign out")
57
57
  }
@@ -0,0 +1,8 @@
1
+
2
+ let authProps = null
3
+
4
+ export const getAuthProps = () => authProps
5
+
6
+ export const setAuthProps = (newAuthProps) => {
7
+ authProps = newAuthProps
8
+ }
package/auth/sign_out.js CHANGED
@@ -1,5 +1,4 @@
1
1
  /* @flow */
2
-
3
2
  import {set_is_signed_in, setUid, set_tenant_id} from "./index"
4
3
 
5
4
  export const sign_out = () => {
@@ -10,5 +9,5 @@ export const sign_out = () => {
10
9
 
11
10
  // TODO: clear DB
12
11
  // https://stackoverflow.com/a/15861765
13
- console.log("TODO clear DB")
12
+ console.log("signout: TODO clear DB")
14
13
  }
@@ -0,0 +1,56 @@
1
+ import {useState} from "react"
2
+
3
+ import page from "../page"
4
+
5
+ import SignIn from "./SignIn"
6
+ import SignUp from "./SignUp"
7
+ import SignOut from "./SignOut"
8
+ import ForgotPassword from "./ForgotPassword"
9
+ import SetNewPassword from "./SetNewPassword"
10
+ import { getAuthProps } from "./authProps"
11
+
12
+ const hasInitialized = false
13
+
14
+ export const useAuthRouter = () => {
15
+ const [authComponent, setAuthComponent] = useState(null)
16
+
17
+ // this method is used because the child component's effects are executed before the parent's one
18
+ if (!hasInitialized) {
19
+ page("/signin", (ctx, next) => {
20
+ const authProps = getAuthProps()
21
+ console.log("AUTHPROPS", authProps)
22
+ setAuthComponent(<SignIn {...authProps} />)
23
+ })
24
+
25
+ page("/signout", (ctx, next) => {
26
+ const authProps = getAuthProps()
27
+ setAuthComponent(
28
+ <SignOut {...authProps} />
29
+ )
30
+ })
31
+
32
+ page("/signup", (ctx, next) => {
33
+ const authProps = getAuthProps()
34
+ console.log("AUTHPROPS", authProps)
35
+ setAuthComponent(<SignUp {...authProps} />)
36
+ })
37
+
38
+ page("/forgot-password", (ctx, next) => {
39
+ const authProps = getAuthProps()
40
+ setAuthComponent(<ForgotPassword {...authProps} />)
41
+ })
42
+
43
+ page("/set-new-password", (ctx, next) => {
44
+ const authProps = getAuthProps()
45
+ setAuthComponent(<SetNewPassword {...authProps} />)
46
+ })
47
+
48
+ page("*", (ctx, next) => {
49
+ setAuthComponent(null)
50
+ next()
51
+ })
52
+
53
+ }
54
+
55
+ return {authComponent}
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.172.0",
3
+ "version": "0.174.0-pagerouterauth.0",
4
4
  "scripts": {
5
5
  "test": "../../node_modules/.bin/wireit"
6
6
  },
@@ -69,7 +69,7 @@ const getUseQuery = (register_query) => (
69
69
  if (options.debug) {
70
70
  console.log("use query", model_name, query, options)
71
71
  }
72
- }, [])
72
+ }, [model_name, query, options])
73
73
 
74
74
  const applyNewData = (newData, context) => {
75
75
  setData(newData)
@@ -99,6 +99,11 @@ const getUseQuery = (register_query) => (
99
99
  useEffect(() => {
100
100
  const queryKey = key || id
101
101
 
102
+ if (!model_name) {
103
+ console.warn("attempting to register query with empty collection, skipping")
104
+ return
105
+ }
106
+
102
107
  if (options.debug ) {
103
108
  console.log("register query", model_name, query, options)
104
109
  }
@@ -165,7 +170,7 @@ const getUseQuery = (register_query) => (
165
170
  }
166
171
 
167
172
  if (isEqual(data, newData) && !isEqualValues(data, newData) && __DEV__) {
168
- alert("EQUALITY MISMATCH THIS SHOULD NOT HAPPPEND!!!", data, newData)
173
+ alert("EQUALITY MISMATCH THIS SHOULD NOT HAPPEN!", data, newData)
169
174
  }
170
175
 
171
176
  if (!isEqualValues(dataRef.current, newData)) {
@@ -187,13 +192,13 @@ const getUseQuery = (register_query) => (
187
192
 
188
193
 
189
194
  const loadNextPage = useCallback(() => {
190
- console.log("will load next page after DOC")
195
+ console.log("NYI: will load next page after DOC")
191
196
  }, [])
192
197
 
193
198
 
194
199
  const result = useMemo(() => ({data, source, error, loading}), [data, source, error, loading])
195
200
 
196
- // TODO: investigate this one
201
+ // TODO:
197
202
  // if (Array.isArray(result.data) && !result.source) {
198
203
  // console.warn("RESULT HAS NO SOURCE", {data, error, loading, source})
199
204
  // }
@@ -22,6 +22,10 @@ const _cols_store = Object.create(null)
22
22
 
23
23
 
24
24
  const get_collection = (col_name) => {
25
+ if (!col_name) {
26
+ console.warn("supplied invalid / empty collection name to rts")
27
+ }
28
+
25
29
  if (_cols_store[col_name]) {
26
30
  return _cols_store[col_name]
27
31
  } else {
package/auth/views.js DELETED
@@ -1,14 +0,0 @@
1
- /* @flow */
2
- import SignIn from "./SignIn"
3
- import SignUp from "./SignUp"
4
- import SignOut from "./SignOut"
5
- import ForgotPassword from "./ForgotPassword"
6
- import SetNewPassword from "./SetNewPassword"
7
-
8
- export {
9
- SignIn,
10
- SignUp,
11
- SignOut,
12
- ForgotPassword,
13
- SetNewPassword,
14
- }