@rpcbase/client 0.18.0 → 0.21.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.
- package/auth/ForgotPassword/index.js +1 -1
- package/auth/SetNewPassword/index.js +2 -2
- package/auth/SignIn/index.js +18 -7
- package/auth/SignUp/index.js +9 -5
- package/auth/index.js +11 -2
- package/package.json +1 -1
|
@@ -79,7 +79,7 @@ const ForgotPassword = ({name, logo}) => {
|
|
|
79
79
|
<p className="text-danger">{errors.form}</p>
|
|
80
80
|
)}
|
|
81
81
|
|
|
82
|
-
<div className="form-floating mb-4">
|
|
82
|
+
<div className="text-start form-floating mb-4">
|
|
83
83
|
<input type="email"
|
|
84
84
|
disabled={isSuccess}
|
|
85
85
|
className="form-control"
|
|
@@ -90,7 +90,7 @@ const SetNewPassword = ({name, logo}) => {
|
|
|
90
90
|
|
|
91
91
|
<form onSubmit={onSubmit}>
|
|
92
92
|
|
|
93
|
-
<div className="form-floating">
|
|
93
|
+
<div className="form-floating text-start">
|
|
94
94
|
<input type="password"
|
|
95
95
|
className="form-control"
|
|
96
96
|
id="input-password1"
|
|
@@ -101,7 +101,7 @@ const SetNewPassword = ({name, logo}) => {
|
|
|
101
101
|
<label htmlFor="input-password1">Password</label>
|
|
102
102
|
</div>
|
|
103
103
|
|
|
104
|
-
<div className="form-floating">
|
|
104
|
+
<div className="form-floating text-start">
|
|
105
105
|
<input type="password"
|
|
106
106
|
className="form-control"
|
|
107
107
|
id="input-password2"
|
package/auth/SignIn/index.js
CHANGED
|
@@ -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
|
-
|
|
46
|
-
|
|
54
|
+
page(redirect)
|
|
55
|
+
} else {
|
|
56
|
+
page(onSuccessRedirect)
|
|
47
57
|
}
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
// errors
|
|
50
59
|
} else {
|
|
60
|
+
log("sign in error", res)
|
|
61
|
+
|
|
51
62
|
setErrors(res.errors)
|
|
52
63
|
}
|
|
53
64
|
}
|
|
@@ -83,7 +94,7 @@ const SignIn = ({
|
|
|
83
94
|
<p className="text-danger">{errors.form}</p>
|
|
84
95
|
)}
|
|
85
96
|
|
|
86
|
-
<div className="form-floating">
|
|
97
|
+
<div className="form-floating text-start">
|
|
87
98
|
<input type="email"
|
|
88
99
|
className="form-control"
|
|
89
100
|
id="input-email"
|
|
@@ -93,7 +104,7 @@ const SignIn = ({
|
|
|
93
104
|
<label htmlFor="input-email">Email Address</label>
|
|
94
105
|
</div>
|
|
95
106
|
|
|
96
|
-
<div className="form-floating">
|
|
107
|
+
<div className="form-floating text-start">
|
|
97
108
|
<input type="password"
|
|
98
109
|
className="form-control"
|
|
99
110
|
id="input-password"
|
package/auth/SignUp/index.js
CHANGED
|
@@ -6,7 +6,11 @@ import Footer from "../Footer"
|
|
|
6
6
|
|
|
7
7
|
import "./sign-up.scss"
|
|
8
8
|
|
|
9
|
-
const SignUp = ({
|
|
9
|
+
const SignUp = ({
|
|
10
|
+
logo,
|
|
11
|
+
name,
|
|
12
|
+
onSuccessRedirect = "/dashboard",
|
|
13
|
+
}) => {
|
|
10
14
|
const [email, setEmail] = useState("")
|
|
11
15
|
const [password, setPassword] = useState("")
|
|
12
16
|
const [passwordConfirm, setPasswordConfirm] = useState("")
|
|
@@ -20,7 +24,7 @@ const SignUp = ({logo, name}) => {
|
|
|
20
24
|
}
|
|
21
25
|
const res = await post("/api/v1/auth/sign_up", {email, password})
|
|
22
26
|
if (res.status === "ok") {
|
|
23
|
-
window.location =
|
|
27
|
+
window.location = onSuccessRedirect
|
|
24
28
|
} else if (res.status === "error") {
|
|
25
29
|
setError(res.message)
|
|
26
30
|
}
|
|
@@ -61,7 +65,7 @@ const SignUp = ({logo, name}) => {
|
|
|
61
65
|
</div>
|
|
62
66
|
)}
|
|
63
67
|
|
|
64
|
-
<div className="form-floating">
|
|
68
|
+
<div className="form-floating text-start">
|
|
65
69
|
<input type="email"
|
|
66
70
|
className="form-control"
|
|
67
71
|
id="input-email"
|
|
@@ -70,7 +74,7 @@ const SignUp = ({logo, name}) => {
|
|
|
70
74
|
onChange={onChangeEmail} />
|
|
71
75
|
<label htmlFor="input-email">Email Address</label>
|
|
72
76
|
</div>
|
|
73
|
-
<div className="form-floating">
|
|
77
|
+
<div className="form-floating text-start">
|
|
74
78
|
<input type="password"
|
|
75
79
|
className="form-control"
|
|
76
80
|
id="input-password"
|
|
@@ -79,7 +83,7 @@ const SignUp = ({logo, name}) => {
|
|
|
79
83
|
onChange={onChangePassword} />
|
|
80
84
|
<label htmlFor="input-password">Password</label>
|
|
81
85
|
</div>
|
|
82
|
-
<div className="form-floating">
|
|
86
|
+
<div className="form-floating text-start">
|
|
83
87
|
<input type="password"
|
|
84
88
|
className="form-control"
|
|
85
89
|
id="input-password-confirm"
|
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
|
|
@@ -42,7 +47,11 @@ const redirect_sign_in = (ctx) => {
|
|
|
42
47
|
|
|
43
48
|
|
|
44
49
|
export const session_restrict = (ctx, next) => {
|
|
50
|
+
log("session_restrict:__is_authenticated", __is_authenticated)
|
|
51
|
+
|
|
45
52
|
if (typeof __is_authenticated !== "boolean") {
|
|
53
|
+
log("session_restrict: will run session check")
|
|
54
|
+
|
|
46
55
|
run_session_check()
|
|
47
56
|
.then(() => {
|
|
48
57
|
if (__is_authenticated) {
|
|
@@ -58,8 +67,8 @@ export const session_restrict = (ctx, next) => {
|
|
|
58
67
|
} else if (__is_authenticated) {
|
|
59
68
|
next()
|
|
60
69
|
} else {
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
log("AUTH", JSON.stringify(__is_authenticated))
|
|
71
|
+
log("NOT AUTHENTICATED, REDIRECT HERE")
|
|
63
72
|
next()
|
|
64
73
|
}
|
|
65
74
|
}
|