@rpcbase/client 0.174.0 → 0.174.1-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.
@@ -6,7 +6,7 @@ import isEmail from "validator/lib/isEmail"
6
6
 
7
7
  import post from "../../helpers/post"
8
8
 
9
- import {set_is_signed_in} from "../index"
9
+ import {setIsSignedIn} from "../index"
10
10
  import Footer from "../Footer"
11
11
 
12
12
  import "./forgot-password.scss"
@@ -6,7 +6,7 @@ import isEmail from "validator/lib/isEmail"
6
6
 
7
7
  import post from "../../helpers/post"
8
8
 
9
- import {set_is_signed_in} from "../index"
9
+ import {setIsSignedIn} from "../index"
10
10
  import Footer from "../Footer"
11
11
 
12
12
  import "./set-new-password.scss"
@@ -8,7 +8,7 @@ import isEmail from "validator/lib/isEmail"
8
8
  import page from "../../page"
9
9
  import post from "../../helpers/post"
10
10
  import {reconnect as rts_reconnect} from "../../rts/rts"
11
- import {set_is_signed_in, setUid, set_tenant_id} from "../index"
11
+ import {setIsSignedIn, setUid, setTenantId} from "../index"
12
12
 
13
13
 
14
14
  const log = debug("rb:auth:signin")
@@ -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)
@@ -4,7 +4,7 @@ import {useState} from "react"
4
4
  import page from "../../page"
5
5
  import {reconnect as rts_reconnect} from "../../rts/rts"
6
6
 
7
- import {set_is_signed_in, setUid, set_tenant_id} from "../index"
7
+ import {setIsSignedIn, setUid, setTenantId} from "../index"
8
8
  import post from "../../helpers/post"
9
9
 
10
10
 
@@ -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)
@@ -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
package/auth/sign_out.js CHANGED
@@ -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
4
  export const sign_out = () => {
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.174.0",
3
+ "version": "0.174.1-pagerouterauth.0",
4
4
  "scripts": {
5
5
  "test": "../../node_modules/.bin/wireit"
6
6
  },