@rpcbase/client 0.150.0 → 0.151.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/SignIn/SignInEmailForm.js +1 -1
- package/auth/SignIn/index.js +1 -1
- package/auth/SignOut/index.js +62 -57
- package/auth/SignUp/index.js +1 -1
- package/package.json +1 -1
- package/src/ui/oauth/GitHub.js +15 -3
- package/src/ui/oauth/getGitHubSigninUrl.js +27 -0
- package/src/ui/oauth/index.js +1 -3
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import assert from "assert"
|
|
3
3
|
import debug from "debug"
|
|
4
4
|
import {useState, useEffect} from "react"
|
|
5
|
-
import
|
|
5
|
+
import useSearchParam from "react-use/lib/useSearchParam"
|
|
6
6
|
import isEmail from "validator/lib/isEmail"
|
|
7
7
|
import page from "page"
|
|
8
8
|
|
package/auth/SignIn/index.js
CHANGED
|
@@ -55,7 +55,7 @@ const SignIn = ({
|
|
|
55
55
|
const Comp = AUTH_BUTTONS[provider.id]
|
|
56
56
|
assert(Comp, `unable to find oauth button for provider: ${JSON.stringify(provider)}`)
|
|
57
57
|
|
|
58
|
-
return <Comp key={`${provider.id}-${index}`} text="Sign in" />
|
|
58
|
+
return <Comp key={`${provider.id}-${index}`} text="Sign in" className="w-100 justify-content-center" />
|
|
59
59
|
})}
|
|
60
60
|
|
|
61
61
|
|
package/auth/SignOut/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import {ActivityIndicator} from "react-native"
|
|
|
5
5
|
import Alert from "react-bootstrap/Alert"
|
|
6
6
|
import page from "page"
|
|
7
7
|
|
|
8
|
+
import authConfig from "@rpcbase/dot-rb/auth"
|
|
9
|
+
|
|
8
10
|
import {sign_out} from "../sign_out"
|
|
9
11
|
|
|
10
12
|
import post from "../../helpers/post"
|
|
@@ -16,6 +18,7 @@ import "./sign-out.scss"
|
|
|
16
18
|
|
|
17
19
|
// TODO: rts_disconnect
|
|
18
20
|
// TODO: clear cache + db
|
|
21
|
+
const hasMultiAccounts = authConfig.has_multi_accounts
|
|
19
22
|
|
|
20
23
|
const SignOut = ({
|
|
21
24
|
logo,
|
|
@@ -30,6 +33,8 @@ const SignOut = ({
|
|
|
30
33
|
|
|
31
34
|
|
|
32
35
|
useEffect(() => {
|
|
36
|
+
if (!hasMultiAccounts) return
|
|
37
|
+
|
|
33
38
|
const load = async() => {
|
|
34
39
|
const res = await post("/api/v1/auth/get_accounts")
|
|
35
40
|
assert(res.status === "ok")
|
|
@@ -41,6 +46,7 @@ const SignOut = ({
|
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
const signOut = async() => {
|
|
49
|
+
// TODO: NYI handle sign out from multiple accounts here
|
|
44
50
|
const res = await post("/api/v1/auth/sign_out")
|
|
45
51
|
if (res.status === "ok") {
|
|
46
52
|
sign_out()
|
|
@@ -57,6 +63,8 @@ const SignOut = ({
|
|
|
57
63
|
signOut()
|
|
58
64
|
}
|
|
59
65
|
|
|
66
|
+
const message = hasMultiAccounts ? "Select accounts to sign out of:" : "Click here to sign out of your account:"
|
|
67
|
+
|
|
60
68
|
return (
|
|
61
69
|
<div id="sign-out-wrapper">
|
|
62
70
|
|
|
@@ -66,63 +74,60 @@ const SignOut = ({
|
|
|
66
74
|
</Alert>
|
|
67
75
|
)}
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
)}
|
|
124
|
-
|
|
125
|
-
</div>) : <div className="h-100"/>}
|
|
77
|
+
<div className="form-signout text-center px-4 py-4 shadow-lg">
|
|
78
|
+
|
|
79
|
+
<div className="d-flex align-items-center justify-content-center">
|
|
80
|
+
{logo}
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<hr />
|
|
84
|
+
|
|
85
|
+
<h1 className="h4 mt-3 mb-3 fw-normal">Sign Out</h1>
|
|
86
|
+
|
|
87
|
+
<p className="text-start text-muted">
|
|
88
|
+
{message}
|
|
89
|
+
</p>
|
|
90
|
+
|
|
91
|
+
{hasMultiAccounts && Array.isArray(accounts) && accounts.length > 0 && (
|
|
92
|
+
<ul className="list-group text-start">
|
|
93
|
+
{accounts.map((acc, index) => {
|
|
94
|
+
const id = `acc-${acc.user_id}-${index}`
|
|
95
|
+
|
|
96
|
+
const onChange = (e) => {
|
|
97
|
+
if (e.target.checked) {
|
|
98
|
+
setSelectedAccounts((prev) => [...prev, acc.user_id])
|
|
99
|
+
} else {
|
|
100
|
+
setSelectedAccounts((prev) => [...prev.filter((v) => v !== acc.user_id)])
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const checked = selectedAccounts.includes(acc.user_id)
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<li key={id} className="list-group-item">
|
|
108
|
+
<input className="form-check-input me-3" type="checkbox" value="" checked={checked} onChange={onChange} id={id} />
|
|
109
|
+
<label className="form-check-label stretched-link" for={id}>
|
|
110
|
+
<AccountListItem
|
|
111
|
+
account={acc}
|
|
112
|
+
// onClick={onClickAccount}
|
|
113
|
+
/>
|
|
114
|
+
</label>
|
|
115
|
+
</li>
|
|
116
|
+
)
|
|
117
|
+
})}
|
|
118
|
+
</ul>
|
|
119
|
+
)}
|
|
120
|
+
|
|
121
|
+
<button className={cx("mb-3 w-100 btn btn-lg btn-primary", hasMultiAccounts ? "mt-4" : "mt-1")} type="submit" onClick={onSubmit}>Sign Out</button>
|
|
122
|
+
|
|
123
|
+
{hasMultiAccounts && Array.isArray(accounts) && accounts.length === 0 && (
|
|
124
|
+
<p className="text-start text-muted">
|
|
125
|
+
You aren't signed in to any accounts<br />
|
|
126
|
+
Go to: <a href="/signin">/signin</a>
|
|
127
|
+
</p>
|
|
128
|
+
)}
|
|
129
|
+
|
|
130
|
+
</div>
|
|
126
131
|
|
|
127
132
|
<Footer name={name} />
|
|
128
133
|
|
package/auth/SignUp/index.js
CHANGED
|
@@ -55,7 +55,7 @@ const SignUp = ({
|
|
|
55
55
|
const Comp = AUTH_BUTTONS[provider.id]
|
|
56
56
|
assert(Comp, `unable to find oauth button for provider: ${JSON.stringify(provider)}`)
|
|
57
57
|
|
|
58
|
-
return <Comp key={`${provider.id}-${index}`} text="Sign up"/>
|
|
58
|
+
return <Comp key={`${provider.id}-${index}`} text="Sign up" className="w-100 justify-content-center" />
|
|
59
59
|
})}
|
|
60
60
|
</div>
|
|
61
61
|
</div>
|
package/package.json
CHANGED
package/src/ui/oauth/GitHub.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
/* @flow */
|
|
2
|
+
import {useEffect, useState} from "react"
|
|
3
|
+
import useLocation from "react-use/lib/useLocation"
|
|
2
4
|
|
|
5
|
+
import getGitHubSigninUrl from "./getGitHubSigninUrl"
|
|
3
6
|
|
|
4
|
-
|
|
7
|
+
|
|
8
|
+
export const GitHub = ({text, className = ""}) => {
|
|
9
|
+
const location = useLocation()
|
|
10
|
+
|
|
11
|
+
const [url, setUrl] = useState(getGitHubSigninUrl())
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const newUrl = getGitHubSigninUrl()
|
|
15
|
+
setUrl(newUrl)
|
|
16
|
+
}, [location])
|
|
5
17
|
|
|
6
18
|
return (
|
|
7
|
-
<a href=
|
|
8
|
-
className="sign-in-github-btn p-2 btn-lg
|
|
19
|
+
<a href={url}
|
|
20
|
+
className={cx("sign-in-github-btn p-2 btn-lg", className)}
|
|
9
21
|
style={{}}>
|
|
10
22
|
<div style={{}} className="me-2">
|
|
11
23
|
<svg height="28px" width="28px" viewBox="0 0 16 16" style={{fill: "currentColor"}}>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
import {GITHUB_OAUTH_CLIENT_ID} from "env"
|
|
3
|
+
|
|
4
|
+
// https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes
|
|
5
|
+
const DEFAULT_SCOPES = []
|
|
6
|
+
|
|
7
|
+
const getGitHubSigninUrl = () => {
|
|
8
|
+
const params = new URLSearchParams(window.location.search)
|
|
9
|
+
const scopes = params.get("scopes") || ""
|
|
10
|
+
const state = params.get("state")
|
|
11
|
+
|
|
12
|
+
let reqScopes = DEFAULT_SCOPES.join("")
|
|
13
|
+
if (reqScopes && scopes) {
|
|
14
|
+
reqScopes += `%20${scopes}`
|
|
15
|
+
} else if (scopes) {
|
|
16
|
+
reqScopes = scopes
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let authUrl = "https://github.com/login/oauth/authorize?client_id=" + GITHUB_OAUTH_CLIENT_ID + `&scope=${reqScopes}`
|
|
20
|
+
if (state) {
|
|
21
|
+
authUrl += `&state=${state}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return authUrl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default getGitHubSigninUrl
|