@rpcbase/client 0.20.0 → 0.22.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.
@@ -29,7 +29,8 @@ const ForgotPassword = ({name, logo}) => {
29
29
  setEmail(decoded)
30
30
  // remove the hash
31
31
  // isn't there a better way
32
- history.pushState(
32
+ // fixes go back twice on change password
33
+ history.replaceState(
33
34
  "",
34
35
  document.title,
35
36
  window.location.pathname + window.location.search
@@ -2,6 +2,8 @@
2
2
  import {useState, useEffect} from "react"
3
3
  import {useSearchParam} from "react-use"
4
4
  import isEmail from "validator/lib/isEmail"
5
+ import page from "page"
6
+ import debug from "debug"
5
7
 
6
8
  import post from "../../helpers/post"
7
9
 
@@ -10,6 +12,10 @@ import Footer from "../Footer"
10
12
 
11
13
  import "./sign-in.scss"
12
14
 
15
+
16
+ const log = debug("rb:auth:signin")
17
+
18
+
13
19
  const SignIn = ({
14
20
  name,
15
21
  logo,
@@ -25,7 +31,6 @@ const SignIn = ({
25
31
  const redirect = useSearchParam("redirect")
26
32
 
27
33
  useEffect(() => {
28
- console.log("email changed", email)
29
34
  if (isEmail(email)) {
30
35
  setForgotUrlParam(btoa(email))
31
36
  } else {
@@ -39,15 +44,21 @@ const SignIn = ({
39
44
  const res = await post("/api/v1/auth/sign_in", {email, password})
40
45
  setIsLoading(false)
41
46
 
47
+ // success
42
48
  if (res.status === "ok") {
49
+ log("signed in res: ok", res)
50
+ log("redirect to:", redirect || onSuccessRedirect)
51
+
43
52
  set_is_signed_in(true)
44
53
  if (redirect) {
45
- window.location = redirect
46
- return
54
+ page(redirect)
55
+ } else {
56
+ page(onSuccessRedirect)
47
57
  }
48
- window.location = onSuccessRedirect
49
-
58
+ // errors
50
59
  } else {
60
+ log("sign in error", res)
61
+
51
62
  setErrors(res.errors)
52
63
  }
53
64
  }
package/auth/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /* @flow */
2
2
  import page from "page"
3
+ import debug from "debug"
3
4
 
4
5
  import SignIn from "./SignIn"
5
6
  import SignUp from "./SignUp"
@@ -19,12 +20,16 @@ export {
19
20
 
20
21
  const UID_STORAGE_KEY = "rb::session-user_id"
21
22
 
23
+ const log = debug("rb:auth")
24
+
22
25
  let __is_authenticated = null
23
26
  let __user_id = localStorage.getItem(UID_STORAGE_KEY)
24
27
 
28
+
25
29
  const run_session_check = async() => {
26
30
  const res = await post("/api/v1/auth/check_session")
27
31
  const {is_signed_in, user_id} = res
32
+ log("check_session response", res)
28
33
  __is_authenticated = is_signed_in
29
34
  __user_id = user_id
30
35
  // cache user_id in localStorage
@@ -33,6 +38,9 @@ const run_session_check = async() => {
33
38
  }
34
39
  }
35
40
 
41
+ // Force trigger run first session check
42
+ run_session_check()
43
+
36
44
  // manually run first check
37
45
  // TODO: this should come from localStorage
38
46
  const redirect_sign_in = (ctx) => {
@@ -42,7 +50,11 @@ const redirect_sign_in = (ctx) => {
42
50
 
43
51
 
44
52
  export const session_restrict = (ctx, next) => {
53
+ log("session_restrict:__is_authenticated", __is_authenticated)
54
+
45
55
  if (typeof __is_authenticated !== "boolean") {
56
+ log("session_restrict: will run session check")
57
+
46
58
  run_session_check()
47
59
  .then(() => {
48
60
  if (__is_authenticated) {
@@ -58,8 +70,8 @@ export const session_restrict = (ctx, next) => {
58
70
  } else if (__is_authenticated) {
59
71
  next()
60
72
  } else {
61
- console.log("AUTH", JSON.stringify(__is_authenticated))
62
- console.log("NOT AUTHENTICATED, REDIRECT HERE")
73
+ log("AUTH", JSON.stringify(__is_authenticated))
74
+ log("NOT AUTHENTICATED, REDIRECT HERE")
63
75
  next()
64
76
  }
65
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 0"
6
6
  },