@mblaney/holster-browser 1.1.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
@@ -14,6 +14,7 @@ Peer dependencies: `@mblaney/holster`, `@mui/material`, `@mui/icons-material`, `
14
14
  import {
15
15
  Login,
16
16
  Register,
17
+ Signup,
17
18
  RequestCode,
18
19
  ValidateEmail,
19
20
  ResetPassword,
@@ -22,7 +23,6 @@ import {
22
23
  LoginCodes,
23
24
  EditCache,
24
25
  SearchAppBar,
25
- registerServiceWorker,
26
26
  useAccountSync,
27
27
  } from "@mblaney/holster-browser"
28
28
  ```
@@ -58,14 +58,59 @@ const appBar = {
58
58
 
59
59
  #### Auth components
60
60
 
61
- `Login`, `Register`, `RequestCode`, `ValidateEmail`, `ResetPassword`, and `UpdatePassword` all accept `user`, `mode`, `setMode`, and `appBar` props. They render a `SearchAppBar` only when the user is already logged in.
61
+ `Login`, `Register`, `Signup`, `RequestCode`, `ValidateEmail`, `ResetPassword`, and `UpdatePassword` render only their own form content (fields, submit button, status message) — no page container, card, or app bar. This keeps holster-browser out of the business of page layout, so each app is free to wrap them however it likes, including its own home nav or logo.
62
+
63
+ `Register` needs the login code supplied up front (obtained via the waitlist flow or shared directly). `Signup` instead has the server assign a login code automatically from a pool (see the `signup` option in [holster-router](https://github.com/mblaney/holster-router)); the code isn't provided by the client, it's sent back in the sign up email that also asks the user to validate their address.
64
+
65
+ Each component's props:
66
+
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
+ | `UpdatePassword` | `user`, `loggedIn`, `current`, `code`, `reset` |
76
+
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.
78
+
79
+ Wrap them in your own layout, e.g.:
80
+
81
+ ```jsx
82
+ const FormLayout = ({loggedIn, mode, setMode, appBar, children}) => (
83
+ <>
84
+ {loggedIn && <SearchAppBar mode={mode} setMode={setMode} {...appBar} />}
85
+ <Container maxWidth="sm">
86
+ <Grid container>
87
+ <Grid item xs={12}>
88
+ <Card sx={{mt: 2}}>
89
+ <CardContent>{children}</CardContent>
90
+ </Card>
91
+ </Grid>
92
+ </Grid>
93
+ </Container>
94
+ </>
95
+ )
96
+
97
+ <FormLayout loggedIn={!!user.is} mode={mode} setMode={setMode} appBar={appBar}>
98
+ <Login user={user} host={host} />
99
+ </FormLayout>
100
+ ```
62
101
 
63
102
  #### Settings
64
103
 
65
104
  A base settings page with name greeting, password change, and logout. Pass app-specific content as `children`, which renders between the greeting and password cards.
66
105
 
67
106
  ```jsx
68
- <Settings user={user} mode={mode} setMode={setMode} appBar={appBar} buildDate={buildDate}>
107
+ <Settings
108
+ user={user}
109
+ mode={mode}
110
+ setMode={setMode}
111
+ appBar={appBar}
112
+ buildDate={buildDate}
113
+ >
69
114
  <LoginCodes user={user} host={host} code={code} />
70
115
  {/* other app-specific settings */}
71
116
  </Settings>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mblaney/holster-browser",
3
- "version": "1.1.0",
3
+ "version": "2.0.1",
4
4
  "description": "React components for holster applications",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -1,13 +1,9 @@
1
1
  import {useRef, useState} from "react"
2
2
  import Box from "@mui/material/Box"
3
3
  import Button from "@mui/material/Button"
4
- import Card from "@mui/material/Card"
5
- import CardContent from "@mui/material/CardContent"
6
4
  import Checkbox from "@mui/material/Checkbox"
7
- import Container from "@mui/material/Container"
8
5
  import FormControl from "@mui/material/FormControl"
9
6
  import FormControlLabel from "@mui/material/FormControlLabel"
10
- import Grid from "@mui/material/Grid"
11
7
  import IconButton from "@mui/material/IconButton"
12
8
  import InputAdornment from "@mui/material/InputAdornment"
13
9
  import InputLabel from "@mui/material/InputLabel"
@@ -16,15 +12,14 @@ import TextField from "@mui/material/TextField"
16
12
  import Typography from "@mui/material/Typography"
17
13
  import Visibility from "@mui/icons-material/Visibility"
18
14
  import VisibilityOff from "@mui/icons-material/VisibilityOff"
19
- import SearchAppBar from "./SearchAppBar.jsx"
20
15
 
21
- const Login = ({user, host, mode, setMode, appBar}) => {
16
+ const Login = ({user, host}) => {
22
17
  const [username, setUsername] = useState("")
23
18
  const [password, setPassword] = useState("")
24
19
  const [showPassword, setShowPassword] = useState(false)
25
20
  const [stayLoggedIn, setStayLoggedIn] = useState(false)
26
21
  const [message, setMessage] = useState(user.is ? "Already logged in" : "")
27
- const [disabledButton, setDisabledButton] = useState(user.is)
22
+ const [disabledButton, setDisabledButton] = useState(!!user.is)
28
23
  const found = useRef(false)
29
24
 
30
25
  const checkAccount = async () => {
@@ -111,79 +106,60 @@ const Login = ({user, host, mode, setMode, appBar}) => {
111
106
 
112
107
  return (
113
108
  <>
114
- {user.is && (
115
- <SearchAppBar mode={mode} setMode={setMode} {...appBar} />
116
- )}
117
- <Container maxWidth="sm">
118
- <Grid container>
119
- <Grid item xs={12}>
120
- <Card sx={{mt: 2}}>
121
- <CardContent>
122
- <Typography variant="h5">Login</Typography>
123
- <TextField
124
- id="login-username"
125
- label="Username"
126
- variant="outlined"
127
- fullWidth={true}
128
- margin="normal"
129
- value={username}
130
- onChange={event => setUsername(event.target.value)}
131
- InputLabelProps={{shrink: true}}
132
- />
133
- <FormControl
134
- variant="outlined"
135
- fullWidth={true}
136
- margin="normal"
137
- value={password}
138
- onChange={event => setPassword(event.target.value)}
139
- >
140
- <InputLabel htmlFor="login-password">Password</InputLabel>
141
- <OutlinedInput
142
- id="login-password"
143
- type={showPassword ? "text" : "password"}
144
- endAdornment={
145
- <InputAdornment position="end">
146
- <IconButton
147
- aria-label="toggle password visibility"
148
- onClick={() => setShowPassword(show => !show)}
149
- edge="end"
150
- >
151
- {showPassword ? <VisibilityOff /> : <Visibility />}
152
- </IconButton>
153
- </InputAdornment>
154
- }
155
- label="Password"
156
- />
157
- </FormControl>
158
- <Box sx={{display: "flex", alignItems: "center", mt: 1}}>
159
- {!user.is && !message && (
160
- <FormControlLabel
161
- control={
162
- <Checkbox
163
- checked={stayLoggedIn}
164
- onChange={e => setStayLoggedIn(e.target.checked)}
165
- />
166
- }
167
- label="Stay logged in"
168
- />
169
- )}
170
- {message && (
171
- <Typography variant="body2">{message}</Typography>
172
- )}
173
- <Button
174
- sx={{ml: "auto"}}
175
- variant="contained"
176
- disabled={disabledButton}
177
- onClick={() => login(username)}
178
- >
179
- Submit
180
- </Button>
181
- </Box>
182
- </CardContent>
183
- </Card>
184
- </Grid>
185
- </Grid>
186
- </Container>
109
+ <Typography variant="h5">Login</Typography>
110
+ <TextField
111
+ id="login-username"
112
+ label="Username"
113
+ variant="outlined"
114
+ fullWidth={true}
115
+ margin="normal"
116
+ value={username}
117
+ onChange={event => setUsername(event.target.value)}
118
+ slotProps={{inputLabel: {shrink: true}}}
119
+ />
120
+ <FormControl variant="outlined" fullWidth={true} margin="normal">
121
+ <InputLabel htmlFor="login-password">Password</InputLabel>
122
+ <OutlinedInput
123
+ id="login-password"
124
+ type={showPassword ? "text" : "password"}
125
+ value={password}
126
+ onChange={event => setPassword(event.target.value)}
127
+ endAdornment={
128
+ <InputAdornment position="end">
129
+ <IconButton
130
+ aria-label="toggle password visibility"
131
+ onClick={() => setShowPassword(show => !show)}
132
+ edge="end"
133
+ >
134
+ {showPassword ? <VisibilityOff /> : <Visibility />}
135
+ </IconButton>
136
+ </InputAdornment>
137
+ }
138
+ label="Password"
139
+ />
140
+ </FormControl>
141
+ <Box sx={{display: "flex", alignItems: "center", mt: 1}}>
142
+ {!user.is && !message && (
143
+ <FormControlLabel
144
+ control={
145
+ <Checkbox
146
+ checked={stayLoggedIn}
147
+ onChange={e => setStayLoggedIn(e.target.checked)}
148
+ />
149
+ }
150
+ label="Stay logged in"
151
+ />
152
+ )}
153
+ {message && <Typography variant="body2">{message}</Typography>}
154
+ <Button
155
+ sx={{ml: "auto"}}
156
+ variant="contained"
157
+ disabled={disabledButton}
158
+ onClick={() => login(username)}
159
+ >
160
+ Submit
161
+ </Button>
162
+ </Box>
187
163
  </>
188
164
  )
189
165
  }
@@ -43,11 +43,7 @@ const LoginCodes = ({user, host, code}) => {
43
43
  }
44
44
 
45
45
  secret = await user.SEA.secret({epub: epub}, user.is)
46
- user
47
- .get([host, "shared"])
48
- .next("login_codes")
49
- .next(code)
50
- .on(update, true)
46
+ user.get([host, "shared"]).next("login_codes").next(code).on(update, true)
51
47
  })
52
48
 
53
49
  return () => {
@@ -1,10 +1,6 @@
1
1
  import {useState} from "react"
2
2
  import Button from "@mui/material/Button"
3
- import Card from "@mui/material/Card"
4
- import CardContent from "@mui/material/CardContent"
5
- import Container from "@mui/material/Container"
6
3
  import FormControl from "@mui/material/FormControl"
7
- import Grid from "@mui/material/Grid"
8
4
  import IconButton from "@mui/material/IconButton"
9
5
  import InputAdornment from "@mui/material/InputAdornment"
10
6
  import InputLabel from "@mui/material/InputLabel"
@@ -13,16 +9,15 @@ import TextField from "@mui/material/TextField"
13
9
  import Typography from "@mui/material/Typography"
14
10
  import Visibility from "@mui/icons-material/Visibility"
15
11
  import VisibilityOff from "@mui/icons-material/VisibilityOff"
16
- import SearchAppBar from "./SearchAppBar.jsx"
17
12
 
18
- const Register = ({user, mode, setMode, appBar}) => {
13
+ const Register = ({user}) => {
19
14
  const [username, setUsername] = useState("")
20
15
  const [password, setPassword] = useState("")
21
16
  const [showPassword, setShowPassword] = useState(false)
22
17
  const [email, setEmail] = useState("")
23
18
  const [code, setCode] = useState("")
24
19
  const [message, setMessage] = useState(user.is ? "Already logged in" : "")
25
- const [disabledButton, setDisabledButton] = useState(user.is)
20
+ const [disabledButton, setDisabledButton] = useState(!!user.is)
26
21
 
27
22
  const register = () => {
28
23
  if (!username) {
@@ -60,13 +55,17 @@ const Register = ({user, mode, setMode, appBar}) => {
60
55
  return
61
56
  }
62
57
 
63
- user.auth(username, password, err => {
58
+ user.auth(username, password, async err => {
64
59
  if (err) {
65
60
  setDisabledButton(false)
66
61
  setMessage(err)
67
62
  return
68
63
  }
69
64
 
65
+ const signed = await user.SEA.sign(
66
+ {username, email, timestamp: Date.now()},
67
+ user.is,
68
+ )
70
69
  fetch(`${window.location.origin}/verify-login-code`, {
71
70
  method: "POST",
72
71
  headers: {"Content-Type": "application/json;charset=utf-8"},
@@ -74,8 +73,7 @@ const Register = ({user, mode, setMode, appBar}) => {
74
73
  code: code,
75
74
  pub: user.is.pub,
76
75
  epub: user.is.epub,
77
- username: username,
78
- email: email,
76
+ signed,
79
77
  }),
80
78
  })
81
79
  .then(res => res.text().then(text => ({ok: res.ok, text: text})))
@@ -97,86 +95,69 @@ const Register = ({user, mode, setMode, appBar}) => {
97
95
 
98
96
  return (
99
97
  <>
100
- {user.is && (
101
- <SearchAppBar mode={mode} setMode={setMode} {...appBar} />
98
+ <Typography variant="h5">Register</Typography>
99
+ <TextField
100
+ id="register-username"
101
+ label="Username"
102
+ variant="outlined"
103
+ fullWidth={true}
104
+ margin="normal"
105
+ value={username}
106
+ onChange={event => setUsername(event.target.value)}
107
+ slotProps={{inputLabel: {shrink: true}}}
108
+ />
109
+ <FormControl variant="outlined" fullWidth={true} margin="normal">
110
+ <InputLabel htmlFor="register-password">Password</InputLabel>
111
+ <OutlinedInput
112
+ id="register-password"
113
+ type={showPassword ? "text" : "password"}
114
+ value={password}
115
+ onChange={event => setPassword(event.target.value)}
116
+ endAdornment={
117
+ <InputAdornment position="end">
118
+ <IconButton
119
+ aria-label="toggle password visibility"
120
+ onClick={() => setShowPassword(show => !show)}
121
+ edge="end"
122
+ >
123
+ {showPassword ? <VisibilityOff /> : <Visibility />}
124
+ </IconButton>
125
+ </InputAdornment>
126
+ }
127
+ label="Password"
128
+ />
129
+ </FormControl>
130
+ <TextField
131
+ id="register-email"
132
+ label="Email"
133
+ variant="outlined"
134
+ fullWidth={true}
135
+ margin="normal"
136
+ value={email}
137
+ onChange={event => setEmail(event.target.value)}
138
+ />
139
+ <TextField
140
+ id="register-code"
141
+ label="Login code"
142
+ variant="outlined"
143
+ fullWidth={true}
144
+ margin="normal"
145
+ value={code}
146
+ onChange={event => setCode(event.target.value)}
147
+ />
148
+ <Button
149
+ sx={{mt: 1}}
150
+ variant="contained"
151
+ disabled={disabledButton}
152
+ onClick={register}
153
+ >
154
+ Submit
155
+ </Button>
156
+ {message && (
157
+ <Typography sx={{m: 1}} variant="string">
158
+ {message}
159
+ </Typography>
102
160
  )}
103
- <Container maxWidth="sm">
104
- <Grid container>
105
- <Grid item xs={12}>
106
- <Card sx={{mt: 2}}>
107
- <CardContent>
108
- <Typography variant="h5">Register</Typography>
109
- <TextField
110
- id="register-username"
111
- label="Username"
112
- variant="outlined"
113
- fullWidth={true}
114
- margin="normal"
115
- value={username}
116
- onChange={event => setUsername(event.target.value)}
117
- InputLabelProps={{shrink: true}}
118
- />
119
- <FormControl
120
- variant="outlined"
121
- fullWidth={true}
122
- margin="normal"
123
- value={password}
124
- onChange={event => setPassword(event.target.value)}
125
- >
126
- <InputLabel htmlFor="register-password">Password</InputLabel>
127
- <OutlinedInput
128
- id="register-password"
129
- type={showPassword ? "text" : "password"}
130
- endAdornment={
131
- <InputAdornment position="end">
132
- <IconButton
133
- aria-label="toggle password visibility"
134
- onClick={() => setShowPassword(show => !show)}
135
- edge="end"
136
- >
137
- {showPassword ? <VisibilityOff /> : <Visibility />}
138
- </IconButton>
139
- </InputAdornment>
140
- }
141
- label="Password"
142
- />
143
- </FormControl>
144
- <TextField
145
- id="register-email"
146
- label="Email"
147
- variant="outlined"
148
- fullWidth={true}
149
- margin="normal"
150
- value={email}
151
- onChange={event => setEmail(event.target.value)}
152
- />
153
- <TextField
154
- id="register-code"
155
- label="Login code"
156
- variant="outlined"
157
- fullWidth={true}
158
- margin="normal"
159
- value={code}
160
- onChange={event => setCode(event.target.value)}
161
- />
162
- <Button
163
- sx={{mt: 1}}
164
- variant="contained"
165
- disabled={disabledButton}
166
- onClick={register}
167
- >
168
- Submit
169
- </Button>
170
- {message && (
171
- <Typography sx={{m: 1}} variant="string">
172
- {message}
173
- </Typography>
174
- )}
175
- </CardContent>
176
- </Card>
177
- </Grid>
178
- </Grid>
179
- </Container>
180
161
  </>
181
162
  )
182
163
  }
@@ -1,14 +1,9 @@
1
1
  import {useState} from "react"
2
2
  import Button from "@mui/material/Button"
3
- import Card from "@mui/material/Card"
4
- import CardContent from "@mui/material/CardContent"
5
- import Container from "@mui/material/Container"
6
- import Grid from "@mui/material/Grid"
7
3
  import TextField from "@mui/material/TextField"
8
4
  import Typography from "@mui/material/Typography"
9
- import SearchAppBar from "./SearchAppBar.jsx"
10
5
 
11
- const RequestCode = ({loggedIn, mode, setMode, appBar}) => {
6
+ const RequestCode = () => {
12
7
  const [email, setEmail] = useState("")
13
8
  const [message, setMessage] = useState("")
14
9
  const [disabledButton, setDisabledButton] = useState(false)
@@ -29,6 +24,10 @@ const RequestCode = ({loggedIn, mode, setMode, appBar}) => {
29
24
  .then(res => res.text().then(text => ({ok: res.ok, text: text})))
30
25
  .then(res => {
31
26
  setDisabledButton(false)
27
+ if (!res.ok) {
28
+ setMessage(res.text)
29
+ return
30
+ }
32
31
  setEmail("")
33
32
  setMessage(res.text)
34
33
  })
@@ -36,42 +35,29 @@ const RequestCode = ({loggedIn, mode, setMode, appBar}) => {
36
35
 
37
36
  return (
38
37
  <>
39
- {loggedIn && (
40
- <SearchAppBar mode={mode} setMode={setMode} {...appBar} />
38
+ <Typography variant="h5">Request login code</Typography>
39
+ <TextField
40
+ id="request-email"
41
+ label="Email"
42
+ variant="outlined"
43
+ fullWidth={true}
44
+ margin="normal"
45
+ value={email}
46
+ onChange={event => setEmail(event.target.value)}
47
+ />
48
+ <Button
49
+ sx={{mt: 1}}
50
+ variant="contained"
51
+ disabled={disabledButton}
52
+ onClick={request}
53
+ >
54
+ Submit
55
+ </Button>
56
+ {message && (
57
+ <Typography sx={{m: 1}} variant="string">
58
+ {message}
59
+ </Typography>
41
60
  )}
42
- <Container maxWidth="sm">
43
- <Grid container>
44
- <Grid item xs={12}>
45
- <Card sx={{mt: 2}}>
46
- <CardContent>
47
- <Typography variant="h5">Request login code</Typography>
48
- <TextField
49
- id="request-email"
50
- label="Email"
51
- variant="outlined"
52
- fullWidth={true}
53
- margin="normal"
54
- value={email}
55
- onChange={event => setEmail(event.target.value)}
56
- />
57
- <Button
58
- sx={{mt: 1}}
59
- variant="contained"
60
- disabled={disabledButton}
61
- onClick={request}
62
- >
63
- Submit
64
- </Button>
65
- {message && (
66
- <Typography sx={{m: 1}} variant="string">
67
- {message}
68
- </Typography>
69
- )}
70
- </CardContent>
71
- </Card>
72
- </Grid>
73
- </Grid>
74
- </Container>
75
61
  </>
76
62
  )
77
63
  }
@@ -1,14 +1,9 @@
1
1
  import {useState} from "react"
2
2
  import Button from "@mui/material/Button"
3
- import Card from "@mui/material/Card"
4
- import CardContent from "@mui/material/CardContent"
5
- import Container from "@mui/material/Container"
6
- import Grid from "@mui/material/Grid"
7
3
  import TextField from "@mui/material/TextField"
8
4
  import Typography from "@mui/material/Typography"
9
- import SearchAppBar from "./SearchAppBar.jsx"
10
5
 
11
- const ResetPassword = ({loggedIn, mode, setMode, appBar}) => {
6
+ const ResetPassword = ({loggedIn}) => {
12
7
  const [email, setEmail] = useState("")
13
8
  const [code, setCode] = useState("")
14
9
  const [message, setMessage] = useState(loggedIn ? "Already logged in" : "")
@@ -27,60 +22,47 @@ const ResetPassword = ({loggedIn, mode, setMode, appBar}) => {
27
22
  headers: {"Content-Type": "application/json;charset=utf-8"},
28
23
  body: JSON.stringify({email: email, code: code}),
29
24
  })
30
- .then(res => res.text())
25
+ .then(res => res.text().then(text => ({ok: res.ok, text: text})))
31
26
  .then(res => {
32
27
  setDisabledButton(false)
33
- setMessage(res)
28
+ setMessage(res.text)
34
29
  })
35
30
  }
36
31
 
37
32
  return (
38
33
  <>
39
- {loggedIn && (
40
- <SearchAppBar mode={mode} setMode={setMode} {...appBar} />
34
+ <Typography variant="h5">Reset Password</Typography>
35
+ <TextField
36
+ id="reset-password-email"
37
+ label="Email"
38
+ variant="outlined"
39
+ fullWidth={true}
40
+ margin="normal"
41
+ value={email}
42
+ onChange={event => setEmail(event.target.value)}
43
+ />
44
+ <TextField
45
+ id="reset-password-code"
46
+ label="Login code"
47
+ variant="outlined"
48
+ fullWidth={true}
49
+ margin="normal"
50
+ value={code}
51
+ onChange={event => setCode(event.target.value)}
52
+ />
53
+ <Button
54
+ sx={{mt: 1}}
55
+ variant="contained"
56
+ disabled={disabledButton}
57
+ onClick={reset}
58
+ >
59
+ Submit
60
+ </Button>
61
+ {message && (
62
+ <Typography sx={{m: 1}} variant="string">
63
+ {message}
64
+ </Typography>
41
65
  )}
42
- <Container maxWidth="sm">
43
- <Grid container>
44
- <Grid item xs={12}>
45
- <Card sx={{mt: 2}}>
46
- <CardContent>
47
- <Typography variant="h5">Reset Password</Typography>
48
- <TextField
49
- id="reset-password-email"
50
- label="Email"
51
- variant="outlined"
52
- fullWidth={true}
53
- margin="normal"
54
- value={email}
55
- onChange={event => setEmail(event.target.value)}
56
- />
57
- <TextField
58
- id="reset-password-code"
59
- label="Login code"
60
- variant="outlined"
61
- fullWidth={true}
62
- margin="normal"
63
- value={code}
64
- onChange={event => setCode(event.target.value)}
65
- />
66
- <Button
67
- sx={{mt: 1}}
68
- variant="contained"
69
- disabled={disabledButton}
70
- onClick={reset}
71
- >
72
- Submit
73
- </Button>
74
- {message && (
75
- <Typography sx={{m: 1}} variant="string">
76
- {message}
77
- </Typography>
78
- )}
79
- </CardContent>
80
- </Card>
81
- </Grid>
82
- </Grid>
83
- </Container>
84
66
  </>
85
67
  )
86
68
  }