@rpcbase/client 0.174.0 → 0.175.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,9 +1,6 @@
1
1
  /* @flow */
2
- import assert from "assert"
3
-
4
- import page from "../../page"
5
- import getInitials from "../../helpers/getInitials"
6
- import Avatar from "../../ui/Avatar"
2
+ import getInitials from "../../../helpers/getInitials"
3
+ import Avatar from "../../../ui/Avatar"
7
4
 
8
5
  import "./account-list-item.scss"
9
6
 
@@ -47,7 +44,7 @@ const getUserName = (user) => {
47
44
  return name
48
45
  }
49
46
 
50
- const AccountListItem = ({account, onClick, avatarProps}) => {
47
+ export const AccountListItem = ({account, onClick, avatarProps}) => {
51
48
 
52
49
  return (
53
50
  <div
@@ -62,5 +59,3 @@ const AccountListItem = ({account, onClick, avatarProps}) => {
62
59
  </div>
63
60
  )
64
61
  }
65
-
66
- export default AccountListItem
@@ -1,8 +1,8 @@
1
1
  /* @flow */
2
- import AccountListItem from "./AccountListItem"
2
+ import {AccountListItem} from "./AccountListItem"
3
3
 
4
4
 
5
- const AccountsList = ({accounts}) => {
5
+ export const AccountsList = ({accounts}) => {
6
6
 
7
7
  return (
8
8
  <>
@@ -15,5 +15,3 @@ const AccountsList = ({accounts}) => {
15
15
  </>
16
16
  )
17
17
  }
18
-
19
- export default AccountsList
@@ -1,8 +1,7 @@
1
1
  /* @flow */
2
-
3
2
  const year = (new Date).getFullYear()
4
3
 
5
- const Footer = ({name}) => {
4
+ export const Footer = ({name}) => {
6
5
 
7
6
  return (
8
7
  <footer className="pt-5 my-5 text-muted border-top">
@@ -10,5 +9,3 @@ const Footer = ({name}) => {
10
9
  </footer>
11
10
  )
12
11
  }
13
-
14
- export default Footer
@@ -4,14 +4,13 @@ import {useHash} from "react-use"
4
4
  import {ActivityIndicator} from "react-native"
5
5
  import isEmail from "validator/lib/isEmail"
6
6
 
7
- import post from "../../helpers/post"
7
+ import post from "../../../helpers/post"
8
8
 
9
- import {set_is_signed_in} from "../index"
10
- import Footer from "../Footer"
9
+ import {Footer} from "../Footer"
11
10
 
12
11
  import "./forgot-password.scss"
13
12
 
14
- const ForgotPassword = ({name, logo}) => {
13
+ export const ForgotPassword = ({name, logo}) => {
15
14
  const [hash, setHash] = useHash()
16
15
 
17
16
  const [isLoading, setIsLoading] = useState(false)
@@ -113,5 +112,3 @@ const ForgotPassword = ({name, logo}) => {
113
112
  </div>
114
113
  )
115
114
  }
116
-
117
- export default ForgotPassword
@@ -2,16 +2,14 @@
2
2
  import {useState, useEffect} from "react"
3
3
  import {useSearchParam} from "react-use"
4
4
  import {ActivityIndicator} from "react-native"
5
- import isEmail from "validator/lib/isEmail"
6
5
 
7
- import post from "../../helpers/post"
6
+ import post from "../../../helpers/post"
8
7
 
9
- import {set_is_signed_in} from "../index"
10
- import Footer from "../Footer"
8
+ import {Footer} from "../Footer"
11
9
 
12
10
  import "./set-new-password.scss"
13
11
 
14
- const SetNewPassword = ({name, logo}) => {
12
+ export const SetNewPassword = ({name, logo}) => {
15
13
  const [isLoading, setIsLoading] = useState(false)
16
14
  const [error, setError] = useState()
17
15
  const [isSuccess, setIsSuccess] = useState(false)
@@ -22,10 +20,6 @@ const SetNewPassword = ({name, logo}) => {
22
20
  const user_id = useSearchParam("uid")
23
21
  const token = useSearchParam("token")
24
22
 
25
- // useEffect(() => {
26
- // console.log("TOKEN", user_id, token)
27
- // }, [user_id, token])
28
-
29
23
  const onSubmit = async(e) => {
30
24
  e.preventDefault()
31
25
 
@@ -134,5 +128,3 @@ const SetNewPassword = ({name, logo}) => {
134
128
  </div>
135
129
  )
136
130
  }
137
-
138
- export default SetNewPassword
@@ -5,15 +5,15 @@ import {useState, useEffect} from "react"
5
5
  import useSearchParam from "react-use/lib/useSearchParam"
6
6
  import isEmail from "validator/lib/isEmail"
7
7
 
8
- import page from "../../page"
9
- import post from "../../helpers/post"
10
- import {reconnect as rts_reconnect} from "../../rts/rts"
11
- import {set_is_signed_in, setUid, set_tenant_id} from "../index"
8
+ import page from "../../../page"
9
+ import post from "../../../helpers/post"
10
+ import {reconnect as rts_reconnect} from "../../../rts/rts"
11
+ import {setIsSignedIn, setUid, setTenantId} from "../../index"
12
12
 
13
13
 
14
14
  const log = debug("rb:auth:signin")
15
15
 
16
- const SignInEmailForm = ({onSuccess, onSuccessRedirect}) => {
16
+ export const SignInEmailForm = ({onSuccess, onSuccessRedirect}) => {
17
17
  const redirect = useSearchParam("redirect")
18
18
 
19
19
  const [isLoading, setIsLoading] = useState(false)
@@ -47,8 +47,8 @@ const SignInEmailForm = ({onSuccess, onSuccessRedirect}) => {
47
47
 
48
48
  setUid(user_id)
49
49
  const tenantId = user_id.slice(8, 16)
50
- set_tenant_id(tenantId)
51
- set_is_signed_in(true)
50
+ setTenantId(tenantId)
51
+ setIsSignedIn(true)
52
52
 
53
53
  // we must now reconnect on the websocket as we now have a new cookie
54
54
  rts_reconnect(tenantId)
@@ -111,5 +111,3 @@ const SignInEmailForm = ({onSuccess, onSuccessRedirect}) => {
111
111
  </form>
112
112
  )
113
113
  }
114
-
115
- export default SignInEmailForm
@@ -3,10 +3,10 @@ import assert from "assert"
3
3
 
4
4
  import authConfig from "@rpcbase/dot-rb/auth"
5
5
 
6
- import {AUTH_BUTTONS} from "../../src/ui/oauth"
7
- import Footer from "../Footer"
6
+ import {AUTH_BUTTONS} from "../../../src/ui/oauth"
7
+ import {Footer} from "../Footer"
8
8
 
9
- import SignInEmailForm from "./SignInEmailForm"
9
+ import {SignInEmailForm} from "./SignInEmailForm"
10
10
 
11
11
  import "./sign-in.scss"
12
12
 
@@ -14,7 +14,7 @@ import "./sign-in.scss"
14
14
  const hasOAuth = authConfig.oauth_providers?.length > 0
15
15
  const hasEmail = authConfig.has_email_signup
16
16
 
17
- const SignIn = ({
17
+ export const SignIn = ({
18
18
  name,
19
19
  logo,
20
20
  onSuccessRedirect = "/",
@@ -66,5 +66,3 @@ const SignIn = ({
66
66
  </div>
67
67
  )
68
68
  }
69
-
70
- export default SignIn
@@ -1,18 +1,16 @@
1
1
  /* @flow */
2
2
  import assert from "assert"
3
3
  import {useState, useEffect} from "react"
4
- import {ActivityIndicator} from "react-native"
5
4
  import Alert from "react-bootstrap/Alert"
6
5
 
7
6
  import authConfig from "@rpcbase/dot-rb/auth"
8
7
 
9
- import page from "../../page"
10
- import {sign_out} from "../sign_out"
8
+ import {signOut} from "../../signOut"
11
9
 
12
- import post from "../../helpers/post"
10
+ import post from "../../../helpers/post"
13
11
 
14
- import AccountListItem from "../AccountsList/AccountListItem"
15
- import Footer from "../Footer"
12
+ import {AccountListItem} from "../AccountsList/AccountListItem"
13
+ import {Footer} from "../Footer"
16
14
 
17
15
  import "./sign-out.scss"
18
16
 
@@ -20,7 +18,7 @@ import "./sign-out.scss"
20
18
  // TODO: clear cache + db
21
19
  const hasMultiAccounts = authConfig.has_multi_accounts
22
20
 
23
- const SignOut = ({
21
+ export const SignOut = ({
24
22
  logo,
25
23
  name,
26
24
  onSignOutSuccess = () => null
@@ -45,11 +43,11 @@ const SignOut = ({
45
43
  }, [])
46
44
 
47
45
 
48
- const signOut = async() => {
46
+ const onSignOut = async() => {
49
47
  // TODO: NYI handle sign out from multiple accounts here
50
48
  const res = await post("/api/v1/auth/sign_out")
51
49
  if (res.status === "ok") {
52
- sign_out()
50
+ signOut()
53
51
  setIsSignedOut(true)
54
52
  onSignOutSuccess()
55
53
  } else {
@@ -60,7 +58,7 @@ const SignOut = ({
60
58
 
61
59
  const onSubmit = () => {
62
60
  console.log("sign out from selected accounts", selectedAccounts)
63
- signOut()
61
+ onSignOut()
64
62
  }
65
63
 
66
64
  const message = hasMultiAccounts ? "Select accounts to sign out of:" : "Click here to sign out of your account:"
@@ -134,5 +132,3 @@ const SignOut = ({
134
132
  </div>
135
133
  )
136
134
  }
137
-
138
- export default SignOut
@@ -1,14 +1,14 @@
1
1
  /* @flow */
2
2
  import {useState} from "react"
3
3
 
4
- import page from "../../page"
5
- import {reconnect as rts_reconnect} from "../../rts/rts"
4
+ import page from "../../../page"
5
+ import {reconnect as rts_reconnect} from "../../../rts/rts"
6
6
 
7
- import {set_is_signed_in, setUid, set_tenant_id} from "../index"
8
- import post from "../../helpers/post"
7
+ import {setIsSignedIn, setUid, setTenantId} from "../../index"
8
+ import post from "../../../helpers/post"
9
9
 
10
10
 
11
- const SignUpEmailForm = ({onSuccessRedirect, onSuccess}) => {
11
+ export const SignUpEmailForm = ({onSuccessRedirect, onSuccess}) => {
12
12
  const [email, setEmail] = useState("")
13
13
  const [password, setPassword] = useState("")
14
14
  const [passwordConfirm, setPasswordConfirm] = useState("")
@@ -27,8 +27,8 @@ const SignUpEmailForm = ({onSuccessRedirect, onSuccess}) => {
27
27
  setUid(user_id)
28
28
 
29
29
  const tenantId = user_id.slice(8, 16)
30
- set_tenant_id(tenantId)
31
- set_is_signed_in(true)
30
+ setTenantId(tenantId)
31
+ setIsSignedIn(true)
32
32
 
33
33
  // we must now reconnect on the websocket as we have a new cookie
34
34
  rts_reconnect(tenantId)
@@ -97,5 +97,3 @@ const SignUpEmailForm = ({onSuccessRedirect, onSuccess}) => {
97
97
  </>
98
98
  )
99
99
  }
100
-
101
- export default SignUpEmailForm
@@ -3,11 +3,11 @@ import assert from "assert"
3
3
 
4
4
  import authConfig from "@rpcbase/dot-rb/auth"
5
5
 
6
- import {AUTH_BUTTONS} from "../../src/ui/oauth"
6
+ import {AUTH_BUTTONS} from "../../../src/ui/oauth"
7
7
 
8
- import Footer from "../Footer"
8
+ import {Footer} from "../Footer"
9
9
 
10
- import SignUpEmailForm from "./SignUpEmailForm"
10
+ import {SignUpEmailForm} from "./SignUpEmailForm"
11
11
 
12
12
  import "./sign-up.scss"
13
13
 
@@ -15,7 +15,7 @@ import "./sign-up.scss"
15
15
  const hasOAuth = authConfig.oauth_providers?.length > 0
16
16
  const hasEmail = authConfig.has_email_signup
17
17
 
18
- const SignUp = ({
18
+ export const SignUp = ({
19
19
  logo,
20
20
  name,
21
21
  onSuccessRedirect = "/",
@@ -64,5 +64,3 @@ const SignUp = ({
64
64
  </div>
65
65
  )
66
66
  }
67
-
68
- export default SignUp
@@ -1,11 +1,9 @@
1
1
  /* @flow */
2
2
 
3
- const redirect_sign_in = (ctx) => {
3
+ export const redirectSignIn = (ctx) => {
4
4
  console.log("REDIRECT SIGN IN NYI NATIVE")
5
5
  console.log("CTX", ctx)
6
6
 
7
7
  // const redirect_path = ctx.canonicalPath
8
8
  // page.redirect(`/signin?redirect=${encodeURIComponent(redirect_path)}`)
9
9
  }
10
-
11
- export default redirect_sign_in
@@ -1,9 +1,7 @@
1
1
  /* @flow */
2
2
  import page from "../../page"
3
3
 
4
- const redirect_sign_in = (ctx) => {
4
+ export const redirectSignIn = (ctx) => {
5
5
  const redirect_path = ctx.canonicalPath
6
6
  page.redirect(`/signin?redirect=${encodeURIComponent(redirect_path)}`)
7
7
  }
8
-
9
- export default redirect_sign_in
package/auth/index.js CHANGED
@@ -4,26 +4,26 @@ import {Platform} from "react-native"
4
4
  import isHexadecimal from "validator/lib/isHexadecimal"
5
5
 
6
6
  import storage from "../storage"
7
- import {disconnect as rts_disconnect} from "../rts/rts"
7
+ import {disconnect as rtsDisconnect} from "../rts/rts"
8
8
  import post from "../helpers/post"
9
9
 
10
- import redirect_sign_in from "./helpers/redirect_sign_in"
10
+ import {redirectSignIn} from "./helpers/redirectSignIn"
11
11
 
12
12
 
13
13
  const LAST_TENANT_KEY = "rb.last_tenant_id"
14
- const uid_storage_key = (tenant_id) => `rb.${tenant_id}.user_id`
14
+ const uidStorageKey = (tenant_id) => `rb.${tenant_id}.user_id`
15
15
 
16
16
  const log = debug("rb:auth")
17
17
 
18
18
  // TODO: this should be refactored to AuthContext + Provider
19
19
 
20
- let __is_authenticated = null
20
+ let __isAuthenticated = null
21
21
 
22
- let __tenant_id = typeof storage !== "undefined" && storage.getItem(LAST_TENANT_KEY)
23
- let __user_id = typeof storage !== "undefined" && __tenant_id && storage.getItem(uid_storage_key(__tenant_id))
22
+ let __tenantId = typeof storage !== "undefined" && storage.getItem(LAST_TENANT_KEY)
23
+ let __userId = typeof storage !== "undefined" && __tenantId && storage.getItem(uidStorageKey(__tenantId))
24
24
 
25
25
 
26
- const get_querystring_auth_id = () => {
26
+ const getQueryStringAuthId = () => {
27
27
  const url = new URL(window.location.href)
28
28
  const val = url.searchParams.get("auth_id")
29
29
  if (!val) return null
@@ -34,14 +34,14 @@ const get_querystring_auth_id = () => {
34
34
  }
35
35
 
36
36
 
37
- const run_session_check = async() => {
37
+ const runSessionCheck = async() => {
38
38
  // TODO: TMP: we're skipping the session check on mobile for now,
39
39
  // this assumes having a token on mobile means we're authenticated
40
40
  if (Platform.OS !== "web") {
41
41
  return
42
42
  }
43
43
 
44
- const auth_user_id = get_querystring_auth_id()
44
+ const auth_user_id = getQueryStringAuthId()
45
45
 
46
46
  if (auth_user_id) {
47
47
  log("check_session with auth user_id", auth_user_id)
@@ -51,27 +51,27 @@ const run_session_check = async() => {
51
51
 
52
52
  log("check_session response", res)
53
53
 
54
- __is_authenticated = res.is_signed_in
54
+ __isAuthenticated = res.is_signed_in
55
55
 
56
56
 
57
- // if not authenticated, clear __user_id + __tenant_id and disconnect socket
58
- if (!__is_authenticated) {
59
- __user_id = null
60
- __tenant_id = null
61
- rts_disconnect()
57
+ // if not authenticated, clear __userId + __tenantId and disconnect socket
58
+ if (!__isAuthenticated) {
59
+ __userId = null
60
+ __tenantId = null
61
+ rtsDisconnect()
62
62
  return
63
63
  }
64
64
 
65
- __user_id = res.user_id
66
- __tenant_id = __user_id.slice(8, 16)
65
+ __userId = res.user_id
66
+ __tenantId = __userId.slice(8, 16)
67
67
 
68
68
  // save tenant id
69
- if (__tenant_id) {
70
- storage.setItem(LAST_TENANT_KEY, __tenant_id)
69
+ if (__tenantId) {
70
+ storage.setItem(LAST_TENANT_KEY, __tenantId)
71
71
 
72
72
  // cache user_id in storage
73
- if (__user_id) {
74
- storage.setItem(uid_storage_key(__tenant_id), __user_id)
73
+ if (__userId) {
74
+ storage.setItem(uidStorageKey(__tenantId), __userId)
75
75
  }
76
76
  }
77
77
  }
@@ -79,54 +79,54 @@ const run_session_check = async() => {
79
79
 
80
80
  // Force trigger run first session check (when we are not in a webworker (or mobile))
81
81
  const isJest = !!process?.env?.JEST_WORKER_ID
82
- if (typeof window !== "undefined" && !isJest) run_session_check()
82
+ if (typeof window !== "undefined" && !isJest) runSessionCheck()
83
83
 
84
84
 
85
- export const session_restrict = (ctx, next) => {
86
- log("session_restrict:__is_authenticated", __is_authenticated)
85
+ export const getSessionRestrictMiddleware = () => (ctx, next) => {
86
+ log("session_restrict:__isAuthenticated", __isAuthenticated)
87
87
 
88
- if (typeof __is_authenticated !== "boolean") {
88
+ if (typeof __isAuthenticated !== "boolean") {
89
89
  log("session_restrict: will run session check")
90
90
 
91
- run_session_check()
91
+ runSessionCheck()
92
92
  .then(() => {
93
- if (__is_authenticated) {
93
+ if (__isAuthenticated) {
94
94
  next()
95
95
  } else {
96
- redirect_sign_in(ctx)
96
+ redirectSignIn(ctx)
97
97
  }
98
98
  })
99
99
  .catch((err) => {
100
100
  console.log("warning error in check session request", err)
101
101
  throw err
102
102
  })
103
- } else if (__is_authenticated) {
103
+ } else if (__isAuthenticated) {
104
104
  next()
105
105
  } else {
106
- log("AUTH", JSON.stringify(__is_authenticated))
106
+ log("AUTH", JSON.stringify(__isAuthenticated))
107
107
  log("NOT AUTHENTICATED, REDIRECT HERE")
108
- redirect_sign_in(ctx)
108
+ redirectSignIn(ctx)
109
109
  // next()
110
110
  }
111
111
  }
112
112
 
113
113
 
114
- export const privateGetUid = () => __user_id
114
+ export const privateGetUid = () => __userId
115
115
  export const setUid = (val) => {
116
- __user_id = val
116
+ __userId = val
117
117
 
118
118
  if (typeof val === "string") {
119
119
  const tenant_id_prefix = val.slice(8, 16)
120
- storage.setItem(uid_storage_key(tenant_id_prefix), val)
120
+ storage.setItem(uidStorageKey(tenant_id_prefix), val)
121
121
  }
122
122
  }
123
123
 
124
- export const getTenantId = () => __tenant_id
125
- export const set_tenant_id = (val) => {
126
- __tenant_id = val
124
+ export const getTenantId = () => __tenantId
125
+ export const setTenantId = (val) => {
126
+ __tenantId = val
127
127
  storage.setItem(LAST_TENANT_KEY, val)
128
128
  }
129
129
 
130
- export const set_is_signed_in = (val) => __is_authenticated = val
130
+ export const setIsSignedIn = (val) => __isAuthenticated = val
131
131
 
132
- export const is_signed_in = () => __is_authenticated
132
+ export const getIsSignedIn = () => __isAuthenticated
@@ -1,10 +1,10 @@
1
1
  /* @flow */
2
- import {set_is_signed_in, setUid, set_tenant_id} from "./index"
2
+ import {setIsSignedIn, setUid, setTenantId} from "./index"
3
3
 
4
- export const sign_out = () => {
4
+ export const signOut = () => {
5
5
  setUid(null)
6
- set_tenant_id(null)
7
- set_is_signed_in(false)
6
+ setTenantId(null)
7
+ setIsSignedIn(false)
8
8
  localStorage.clear()
9
9
 
10
10
  // TODO: clear DB
@@ -2,11 +2,11 @@ import {useState} from "react"
2
2
 
3
3
  import page from "../page"
4
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"
5
+ import {SignIn} from "./components/SignIn"
6
+ import {SignUp} from "./components/SignUp"
7
+ import {SignOut} from "./components/SignOut"
8
+ import {ForgotPassword} from "./components/ForgotPassword"
9
+ import {SetNewPassword} from "./components/SetNewPassword"
10
10
  import { getAuthProps } from "./authProps"
11
11
 
12
12
  const hasInitialized = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.174.0",
3
+ "version": "0.175.0",
4
4
  "scripts": {
5
5
  "test": "../../node_modules/.bin/wireit"
6
6
  },
File without changes
File without changes