@rpcbase/client 0.173.0 → 0.174.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,21 @@ 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.start()
54
+ }, [])
55
+
49
56
  return (
50
57
  <PostHogWrapper>
51
58
  <HashStateProvider>
52
- {children}
59
+ <div className={cx({"d-none": !!authComponent})}>
60
+ {children}
61
+ </div>
62
+ {authComponent}
53
63
  </HashStateProvider>
54
64
  </PostHogWrapper>
55
65
  )
@@ -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.173.0",
3
+ "version": "0.174.0",
4
4
  "scripts": {
5
5
  "test": "../../node_modules/.bin/wireit"
6
6
  },
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
- }