@mblaney/holster-browser 2.0.0 → 2.0.1
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/README.md
CHANGED
|
@@ -64,14 +64,14 @@ const appBar = {
|
|
|
64
64
|
|
|
65
65
|
Each component's props:
|
|
66
66
|
|
|
67
|
-
| Component
|
|
68
|
-
|
|
|
69
|
-
| `Login`
|
|
70
|
-
| `Register`
|
|
71
|
-
| `Signup`
|
|
72
|
-
| `RequestCode`
|
|
73
|
-
| `ValidateEmail`
|
|
74
|
-
| `ResetPassword`
|
|
67
|
+
| Component | Props |
|
|
68
|
+
| ---------------- | ---------------------------------------------- |
|
|
69
|
+
| `Login` | `user`, `host` |
|
|
70
|
+
| `Register` | `user` |
|
|
71
|
+
| `Signup` | `user` |
|
|
72
|
+
| `RequestCode` | _(none)_ |
|
|
73
|
+
| `ValidateEmail` | `code`, `validate` |
|
|
74
|
+
| `ResetPassword` | `loggedIn` |
|
|
75
75
|
| `UpdatePassword` | `user`, `loggedIn`, `current`, `code`, `reset` |
|
|
76
76
|
|
|
77
77
|
`ValidateEmail`'s `code`/`validate` and `UpdatePassword`'s `current`/`code`/`reset` come from the query params on the links in the sign up and reset-password emails respectively.
|
package/package.json
CHANGED
|
@@ -55,13 +55,17 @@ const Register = ({user}) => {
|
|
|
55
55
|
return
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
user.auth(username, password, err => {
|
|
58
|
+
user.auth(username, password, async err => {
|
|
59
59
|
if (err) {
|
|
60
60
|
setDisabledButton(false)
|
|
61
61
|
setMessage(err)
|
|
62
62
|
return
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
const signed = await user.SEA.sign(
|
|
66
|
+
{username, email, timestamp: Date.now()},
|
|
67
|
+
user.is,
|
|
68
|
+
)
|
|
65
69
|
fetch(`${window.location.origin}/verify-login-code`, {
|
|
66
70
|
method: "POST",
|
|
67
71
|
headers: {"Content-Type": "application/json;charset=utf-8"},
|
|
@@ -69,8 +73,7 @@ const Register = ({user}) => {
|
|
|
69
73
|
code: code,
|
|
70
74
|
pub: user.is.pub,
|
|
71
75
|
epub: user.is.epub,
|
|
72
|
-
|
|
73
|
-
email: email,
|
|
76
|
+
signed,
|
|
74
77
|
}),
|
|
75
78
|
})
|
|
76
79
|
.then(res => res.text().then(text => ({ok: res.ok, text: text})))
|
|
@@ -12,6 +12,7 @@ import Switch from "@mui/material/Switch"
|
|
|
12
12
|
import Toolbar from "@mui/material/Toolbar"
|
|
13
13
|
import Typography from "@mui/material/Typography"
|
|
14
14
|
import AccountCircleIcon from "@mui/icons-material/AccountCircle"
|
|
15
|
+
import ClearIcon from "@mui/icons-material/Clear"
|
|
15
16
|
import DarkModeIcon from "@mui/icons-material/DarkMode"
|
|
16
17
|
import LightModeIcon from "@mui/icons-material/LightMode"
|
|
17
18
|
import MoreIcon from "@mui/icons-material/MoreVert"
|
|
@@ -56,7 +57,7 @@ const StyledInputBase = styled(InputBase, {
|
|
|
56
57
|
})(({theme, collapsed}) => ({
|
|
57
58
|
color: "inherit",
|
|
58
59
|
"& .MuiInputBase-input": {
|
|
59
|
-
padding: theme.spacing(1,
|
|
60
|
+
padding: theme.spacing(1, 4, 1, 0),
|
|
60
61
|
paddingLeft: `calc(1em + ${theme.spacing(4)})`,
|
|
61
62
|
transition: theme.transitions.create("width"),
|
|
62
63
|
width: collapsed ? 0 : "100%",
|
|
@@ -93,6 +94,12 @@ const SearchAppBar = ({
|
|
|
93
94
|
const [anchorEl, setAnchorEl] = useState(null)
|
|
94
95
|
const [mobileMoreAnchorEl, setMobileMoreAnchorEl] = useState(null)
|
|
95
96
|
|
|
97
|
+
const handleClear = () => {
|
|
98
|
+
setSearchValue("")
|
|
99
|
+
onSearch?.("")
|
|
100
|
+
searchInputRef.current?.focus()
|
|
101
|
+
}
|
|
102
|
+
|
|
96
103
|
const isMenuOpen = Boolean(anchorEl)
|
|
97
104
|
const isMobileMenuOpen = Boolean(mobileMoreAnchorEl)
|
|
98
105
|
|
|
@@ -233,6 +240,10 @@ const SearchAppBar = ({
|
|
|
233
240
|
onKeyDown={e => {
|
|
234
241
|
if (e.key === "Enter") {
|
|
235
242
|
const trimmed = searchValue.trim()
|
|
243
|
+
if (trimmed === "") {
|
|
244
|
+
if (onSearch) onSearch("")
|
|
245
|
+
return
|
|
246
|
+
}
|
|
236
247
|
if (trimmed.length >= 3) {
|
|
237
248
|
setSearchValue(trimmed)
|
|
238
249
|
if (onSearch) {
|
|
@@ -240,7 +251,6 @@ const SearchAppBar = ({
|
|
|
240
251
|
} else {
|
|
241
252
|
window.location = `/?search=${encodeURIComponent(trimmed)}`
|
|
242
253
|
}
|
|
243
|
-
searchInputRef.current?.blur()
|
|
244
254
|
}
|
|
245
255
|
} else if (e.key === "Escape") {
|
|
246
256
|
setSearchValue("")
|
|
@@ -249,6 +259,24 @@ const SearchAppBar = ({
|
|
|
249
259
|
}
|
|
250
260
|
}}
|
|
251
261
|
/>
|
|
262
|
+
{searchValue && (
|
|
263
|
+
<IconButton
|
|
264
|
+
size="small"
|
|
265
|
+
aria-label="clear search"
|
|
266
|
+
onClick={event => {
|
|
267
|
+
event.stopPropagation()
|
|
268
|
+
handleClear()
|
|
269
|
+
}}
|
|
270
|
+
sx={{
|
|
271
|
+
position: "absolute",
|
|
272
|
+
right: 4,
|
|
273
|
+
top: "50%",
|
|
274
|
+
transform: "translateY(-50%)",
|
|
275
|
+
}}
|
|
276
|
+
>
|
|
277
|
+
<ClearIcon fontSize="small" />
|
|
278
|
+
</IconButton>
|
|
279
|
+
)}
|
|
252
280
|
</Search>
|
|
253
281
|
<Box sx={{display: {xs: "none", md: "flex"}}}>
|
|
254
282
|
<Switch checked={mode === "dark"} onChange={changeMode} />
|
|
@@ -42,21 +42,24 @@ const Signup = ({user}) => {
|
|
|
42
42
|
return
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
user.auth(username, password, err => {
|
|
45
|
+
user.auth(username, password, async err => {
|
|
46
46
|
if (err) {
|
|
47
47
|
setDisabledButton(false)
|
|
48
48
|
setMessage(err)
|
|
49
49
|
return
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const signed = await user.SEA.sign(
|
|
53
|
+
{username, email, timestamp: Date.now()},
|
|
54
|
+
user.is,
|
|
55
|
+
)
|
|
52
56
|
fetch(`${window.location.origin}/signup`, {
|
|
53
57
|
method: "POST",
|
|
54
58
|
headers: {"Content-Type": "application/json;charset=utf-8"},
|
|
55
59
|
body: JSON.stringify({
|
|
56
60
|
pub: user.is.pub,
|
|
57
61
|
epub: user.is.epub,
|
|
58
|
-
|
|
59
|
-
email: email,
|
|
62
|
+
signed,
|
|
60
63
|
}),
|
|
61
64
|
})
|
|
62
65
|
.then(res => res.text().then(text => ({ok: res.ok, text: text})))
|
|
@@ -12,8 +12,10 @@ import VisibilityOff from "@mui/icons-material/VisibilityOff"
|
|
|
12
12
|
|
|
13
13
|
const UpdatePassword = ({user, loggedIn, current, code, reset}) => {
|
|
14
14
|
const [name, setName] = useState(current ?? "")
|
|
15
|
-
const [
|
|
16
|
-
const [
|
|
15
|
+
const [newPassword, setNewPassword] = useState("")
|
|
16
|
+
const [showNewPassword, setShowNewPassword] = useState(false)
|
|
17
|
+
const [repeatPassword, setRepeatPassword] = useState("")
|
|
18
|
+
const [showRepeatPassword, setShowRepeatPassword] = useState(false)
|
|
17
19
|
const [message, setMessage] = useState(loggedIn ? "Already logged in" : "")
|
|
18
20
|
const [disabledButton, setDisabledButton] = useState(loggedIn)
|
|
19
21
|
|
|
@@ -26,7 +28,7 @@ const UpdatePassword = ({user, loggedIn, current, code, reset}) => {
|
|
|
26
28
|
setDisabledButton(true)
|
|
27
29
|
setMessage("Updating password...")
|
|
28
30
|
|
|
29
|
-
user.create(username,
|
|
31
|
+
user.create(username, newPassword, err => {
|
|
30
32
|
if (err) {
|
|
31
33
|
if (err === "Username already exists") {
|
|
32
34
|
let match = username.match(/^(\w+)\.(\d)$/)
|
|
@@ -48,9 +50,10 @@ const UpdatePassword = ({user, loggedIn, current, code, reset}) => {
|
|
|
48
50
|
return
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
user.auth(username,
|
|
53
|
+
user.auth(username, newPassword, err => {
|
|
52
54
|
if (err) {
|
|
53
55
|
setDisabledButton(false)
|
|
56
|
+
user.delete(username, newPassword)
|
|
54
57
|
setMessage(err)
|
|
55
58
|
return
|
|
56
59
|
}
|
|
@@ -71,7 +74,7 @@ const UpdatePassword = ({user, loggedIn, current, code, reset}) => {
|
|
|
71
74
|
.then(res => {
|
|
72
75
|
if (!res.ok) {
|
|
73
76
|
setDisabledButton(false)
|
|
74
|
-
user.delete(username,
|
|
77
|
+
user.delete(username, newPassword)
|
|
75
78
|
setMessage(res.text)
|
|
76
79
|
return
|
|
77
80
|
}
|
|
@@ -93,6 +96,14 @@ const UpdatePassword = ({user, loggedIn, current, code, reset}) => {
|
|
|
93
96
|
})
|
|
94
97
|
}
|
|
95
98
|
|
|
99
|
+
const submit = () => {
|
|
100
|
+
if (newPassword !== repeatPassword) {
|
|
101
|
+
setMessage("Passwords do not match")
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
update(name)
|
|
105
|
+
}
|
|
106
|
+
|
|
96
107
|
return (
|
|
97
108
|
<>
|
|
98
109
|
<Typography variant="h5">Update Password</Typography>
|
|
@@ -106,31 +117,54 @@ const UpdatePassword = ({user, loggedIn, current, code, reset}) => {
|
|
|
106
117
|
onChange={event => setName(event.target.value)}
|
|
107
118
|
/>
|
|
108
119
|
<FormControl variant="outlined" fullWidth={true} margin="normal">
|
|
109
|
-
<InputLabel htmlFor="update-password">Password</InputLabel>
|
|
120
|
+
<InputLabel htmlFor="update-new-password">New Password</InputLabel>
|
|
121
|
+
<OutlinedInput
|
|
122
|
+
id="update-new-password"
|
|
123
|
+
type={showNewPassword ? "text" : "password"}
|
|
124
|
+
value={newPassword}
|
|
125
|
+
onChange={event => setNewPassword(event.target.value)}
|
|
126
|
+
endAdornment={
|
|
127
|
+
<InputAdornment position="end">
|
|
128
|
+
<IconButton
|
|
129
|
+
aria-label="toggle new password visibility"
|
|
130
|
+
onClick={() => setShowNewPassword(show => !show)}
|
|
131
|
+
edge="end"
|
|
132
|
+
>
|
|
133
|
+
{showNewPassword ? <VisibilityOff /> : <Visibility />}
|
|
134
|
+
</IconButton>
|
|
135
|
+
</InputAdornment>
|
|
136
|
+
}
|
|
137
|
+
label="New Password"
|
|
138
|
+
/>
|
|
139
|
+
</FormControl>
|
|
140
|
+
<FormControl variant="outlined" fullWidth={true} margin="normal">
|
|
141
|
+
<InputLabel htmlFor="update-repeat-password">
|
|
142
|
+
Repeat Password
|
|
143
|
+
</InputLabel>
|
|
110
144
|
<OutlinedInput
|
|
111
|
-
id="update-password"
|
|
112
|
-
type={
|
|
113
|
-
value={
|
|
114
|
-
onChange={event =>
|
|
145
|
+
id="update-repeat-password"
|
|
146
|
+
type={showRepeatPassword ? "text" : "password"}
|
|
147
|
+
value={repeatPassword}
|
|
148
|
+
onChange={event => setRepeatPassword(event.target.value)}
|
|
115
149
|
endAdornment={
|
|
116
150
|
<InputAdornment position="end">
|
|
117
151
|
<IconButton
|
|
118
|
-
aria-label="toggle password visibility"
|
|
119
|
-
onClick={() =>
|
|
152
|
+
aria-label="toggle repeat password visibility"
|
|
153
|
+
onClick={() => setShowRepeatPassword(show => !show)}
|
|
120
154
|
edge="end"
|
|
121
155
|
>
|
|
122
|
-
{
|
|
156
|
+
{showRepeatPassword ? <VisibilityOff /> : <Visibility />}
|
|
123
157
|
</IconButton>
|
|
124
158
|
</InputAdornment>
|
|
125
159
|
}
|
|
126
|
-
label="Password"
|
|
160
|
+
label="Repeat Password"
|
|
127
161
|
/>
|
|
128
162
|
</FormControl>
|
|
129
163
|
<Button
|
|
130
164
|
sx={{mt: 1}}
|
|
131
165
|
variant="contained"
|
|
132
166
|
disabled={disabledButton}
|
|
133
|
-
onClick={
|
|
167
|
+
onClick={submit}
|
|
134
168
|
>
|
|
135
169
|
Submit
|
|
136
170
|
</Button>
|
|
@@ -6,6 +6,7 @@ import Signup from "../Signup.jsx"
|
|
|
6
6
|
function createMockUser({createErr = null, authErr = null, is = null} = {}) {
|
|
7
7
|
const user = {
|
|
8
8
|
is,
|
|
9
|
+
SEA: {sign: vi.fn(() => Promise.resolve("mock-signed"))},
|
|
9
10
|
create: vi.fn((username, password, cb) => cb(createErr)),
|
|
10
11
|
auth: vi.fn((username, password, cb) => {
|
|
11
12
|
if (!authErr) user.is = {pub: "mock-pub", epub: "mock-epub"}
|
|
@@ -117,6 +118,14 @@ describe("Signup Component", () => {
|
|
|
117
118
|
|
|
118
119
|
expect(user.create).toHaveBeenCalledWith("alice", "", expect.any(Function))
|
|
119
120
|
expect(user.auth).toHaveBeenCalledWith("alice", "", expect.any(Function))
|
|
121
|
+
expect(user.SEA.sign).toHaveBeenCalledWith(
|
|
122
|
+
{
|
|
123
|
+
username: "alice",
|
|
124
|
+
email: "alice@test.com",
|
|
125
|
+
timestamp: expect.any(Number),
|
|
126
|
+
},
|
|
127
|
+
{pub: "mock-pub", epub: "mock-epub"},
|
|
128
|
+
)
|
|
120
129
|
expect(fetch).toHaveBeenCalledWith(
|
|
121
130
|
expect.stringContaining("/signup"),
|
|
122
131
|
expect.objectContaining({
|
|
@@ -124,8 +133,7 @@ describe("Signup Component", () => {
|
|
|
124
133
|
body: JSON.stringify({
|
|
125
134
|
pub: "mock-pub",
|
|
126
135
|
epub: "mock-epub",
|
|
127
|
-
|
|
128
|
-
email: "alice@test.com",
|
|
136
|
+
signed: "mock-signed",
|
|
129
137
|
}),
|
|
130
138
|
}),
|
|
131
139
|
)
|