@stanlemon/app-template 0.2.0 → 0.2.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/app.js CHANGED
@@ -4,12 +4,7 @@ import {
4
4
  SimpleUsersDao,
5
5
  } from "@stanlemon/server-with-auth";
6
6
 
7
- const users = new SimpleUsersDao([
8
- {
9
- username: "user",
10
- password: "password",
11
- },
12
- ]);
7
+ const users = new SimpleUsersDao();
13
8
 
14
9
  const app = createAppServer({
15
10
  webpack: "http://localhost:8080",
package/db.json CHANGED
@@ -2,9 +2,11 @@
2
2
  "users": [
3
3
  {
4
4
  "username": "user",
5
- "password": "password",
6
- "id": "857866e3-8f76-4fc1-be6c-9c785fbdf593",
7
- "last_logged_in": "2022-03-06T13:02:35.423-05:00"
5
+ "password": "$2a$10$5oHnfhEv5ezdqcVf7k1KNeQ2VVX4Jv0p5tZmhroqbS117umUBrIJO",
6
+ "id": "defb1788-f2b9-4f74-9a72-f397788592bb",
7
+ "verification_token": "BkWPUmVb9",
8
+ "created_at": "2022-03-08T00:42:01.041Z",
9
+ "last_updated": "2022-03-08T00:42:01.041Z"
8
10
  }
9
11
  ]
10
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stanlemon/app-template",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A template for creating apps using the webdev package.",
5
5
  "author": "Stan Lemon <stanlemon@users.noreply.github.com>",
6
6
  "license": "MIT",
package/src/Input.tsx CHANGED
@@ -9,6 +9,7 @@ export default function Input({
9
9
  onEnter = () => {
10
10
  /* noop */
11
11
  },
12
+ error,
12
13
  }: {
13
14
  type?: string;
14
15
  value?: string;
@@ -16,6 +17,7 @@ export default function Input({
16
17
  placeholder?: string;
17
18
  onChange?: (value: string) => void;
18
19
  onEnter?: () => void;
20
+ error?: string;
19
21
  }) {
20
22
  const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
21
23
  onChange(e.currentTarget.value);
@@ -37,6 +39,7 @@ export default function Input({
37
39
  placeholder={placeholder}
38
40
  value={value}
39
41
  />
42
+ {error && <div>{error}</div>}
40
43
  </>
41
44
  );
42
45
  }
package/src/Login.tsx CHANGED
@@ -71,6 +71,7 @@ export default function Login() {
71
71
  label="Password"
72
72
  value={values.password}
73
73
  onChange={(value) => setValues({ ...values, password: value })}
74
+ onEnter={onSubmit}
74
75
  />
75
76
  <button onClick={onSubmit}>Login</button>
76
77
  </div>
package/src/Register.tsx CHANGED
@@ -4,7 +4,7 @@ import Input from "./Input";
4
4
 
5
5
  // eslint-disable-next-line max-lines-per-function
6
6
  export default function Register() {
7
- const [error, setError] = useState<string | null>(null);
7
+ const [errors, setErrors] = useState<Record<string, string>>({});
8
8
  const [values, setValues] = useState<User>({
9
9
  name: "",
10
10
  email: "",
@@ -17,7 +17,7 @@ export default function Register() {
17
17
  };
18
18
 
19
19
  const onSubmit = () => {
20
- setError(null);
20
+ setErrors({});
21
21
  fetch("/auth/register", {
22
22
  headers: {
23
23
  Accept: "application/json",
@@ -43,10 +43,10 @@ export default function Register() {
43
43
  status: number;
44
44
  data: Record<string, unknown>;
45
45
  }) => {
46
- console.log(ok, status, data);
47
-
48
46
  if (ok) {
49
47
  setSession(data as Session);
48
+ } else {
49
+ setErrors((data as FormErrors).errors);
50
50
  }
51
51
  }
52
52
  )
@@ -57,32 +57,18 @@ export default function Register() {
57
57
 
58
58
  return (
59
59
  <div>
60
- {error && (
61
- <div>
62
- <strong>{error}</strong>
63
- </div>
64
- )}
65
- <Input
66
- label="Name"
67
- value={values.name || ""}
68
- onChange={(value) => setValues({ ...values, name: value })}
69
- />
70
- <Input
71
- type="email"
72
- label="Email"
73
- value={values.email || ""}
74
- onChange={(value) => setValues({ ...values, email: value })}
75
- />
76
60
  <Input
77
61
  label="Username"
78
62
  value={values.username}
79
63
  onChange={(value) => setValues({ ...values, username: value })}
64
+ error={errors.username}
80
65
  />
81
66
  <Input
82
67
  type="password"
83
68
  label="Password"
84
69
  value={values.password}
85
70
  onChange={(value) => setValues({ ...values, password: value })}
71
+ error={errors.password}
86
72
  />
87
73
  <button onClick={onSubmit}>Register</button>
88
74
  </div>