@proteinjs/user-ui 1.11.1 → 1.11.3

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +3 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/src/auth/AuthApi.d.ts +5 -1
  7. package/dist/src/auth/AuthApi.d.ts.map +1 -1
  8. package/dist/src/auth/AuthApi.js +5 -1
  9. package/dist/src/auth/AuthApi.js.map +1 -1
  10. package/dist/src/auth/AuthFormFields.d.ts +18 -0
  11. package/dist/src/auth/AuthFormFields.d.ts.map +1 -0
  12. package/dist/src/auth/AuthFormFields.js +41 -0
  13. package/dist/src/auth/AuthFormFields.js.map +1 -0
  14. package/dist/src/auth/AuthTextField.d.ts +14 -2
  15. package/dist/src/auth/AuthTextField.d.ts.map +1 -1
  16. package/dist/src/auth/AuthTextField.js +5 -3
  17. package/dist/src/auth/AuthTextField.js.map +1 -1
  18. package/dist/src/auth/AuthValidation.d.ts +17 -4
  19. package/dist/src/auth/AuthValidation.d.ts.map +1 -1
  20. package/dist/src/auth/AuthValidation.js +41 -11
  21. package/dist/src/auth/AuthValidation.js.map +1 -1
  22. package/dist/src/pages/ForgotPassword.d.ts.map +1 -1
  23. package/dist/src/pages/ForgotPassword.js +26 -14
  24. package/dist/src/pages/ForgotPassword.js.map +1 -1
  25. package/dist/src/pages/Login.d.ts.map +1 -1
  26. package/dist/src/pages/Login.js +40 -14
  27. package/dist/src/pages/Login.js.map +1 -1
  28. package/dist/src/pages/PasswordReset.d.ts.map +1 -1
  29. package/dist/src/pages/PasswordReset.js +37 -17
  30. package/dist/src/pages/PasswordReset.js.map +1 -1
  31. package/dist/src/pages/Signup.d.ts.map +1 -1
  32. package/dist/src/pages/Signup.js +44 -21
  33. package/dist/src/pages/Signup.js.map +1 -1
  34. package/dist/test/authApi.test.js +12 -0
  35. package/dist/test/authApi.test.js.map +1 -1
  36. package/dist/test/authFormsReadTheirFields.test.d.ts +5 -0
  37. package/dist/test/authFormsReadTheirFields.test.d.ts.map +1 -0
  38. package/dist/test/authFormsReadTheirFields.test.js +595 -0
  39. package/dist/test/authFormsReadTheirFields.test.js.map +1 -0
  40. package/dist/test/authValidation.test.js +43 -8
  41. package/dist/test/authValidation.test.js.map +1 -1
  42. package/dist/test/forgotPasswordAnswer.test.d.ts +5 -0
  43. package/dist/test/forgotPasswordAnswer.test.d.ts.map +1 -0
  44. package/dist/test/forgotPasswordAnswer.test.js +143 -0
  45. package/dist/test/forgotPasswordAnswer.test.js.map +1 -0
  46. package/index.ts +4 -0
  47. package/package.json +2 -2
  48. package/src/auth/AuthApi.ts +7 -1
  49. package/src/auth/AuthFormFields.ts +35 -0
  50. package/src/auth/AuthTextField.tsx +23 -3
  51. package/src/auth/AuthValidation.ts +54 -15
  52. package/src/pages/ForgotPassword.tsx +23 -9
  53. package/src/pages/Login.tsx +27 -8
  54. package/src/pages/PasswordReset.tsx +22 -11
  55. package/src/pages/Signup.tsx +39 -16
  56. package/test/authApi.test.ts +7 -0
  57. package/test/authFormsReadTheirFields.test.tsx +369 -0
  58. package/test/authValidation.test.ts +49 -16
  59. package/test/forgotPasswordAnswer.test.tsx +69 -0
@@ -18,24 +18,55 @@ var validSignup = {
18
18
  password: 'hunter22',
19
19
  confirmPassword: 'hunter22',
20
20
  };
21
+ describe('AuthValidation.login', function () {
22
+ it('accepts an email and a password', function () {
23
+ expect(AuthValidation_1.AuthValidation.login({ email: 'ada@example.com', password: 'hunter22' })).toBeUndefined();
24
+ });
25
+ it('marks every blank field', function () {
26
+ expect(AuthValidation_1.AuthValidation.login({ email: '', password: '' })).toEqual({
27
+ email: 'Enter your email',
28
+ password: 'Enter your password',
29
+ });
30
+ });
31
+ it('treats a whitespace-only email as blank, and marks only the blank field', function () {
32
+ expect(AuthValidation_1.AuthValidation.login({ email: ' ', password: 'hunter22' })).toEqual({ email: 'Enter your email' });
33
+ });
34
+ });
35
+ describe('AuthValidation.forgotPassword', function () {
36
+ it('accepts an email', function () {
37
+ expect(AuthValidation_1.AuthValidation.forgotPassword({ email: 'ada@example.com' })).toBeUndefined();
38
+ });
39
+ it('marks a blank email', function () {
40
+ expect(AuthValidation_1.AuthValidation.forgotPassword({ email: ' ' })).toEqual({ email: 'Enter your email' });
41
+ });
42
+ });
21
43
  describe('AuthValidation.signup', function () {
22
44
  it('accepts a complete, matching signup', function () {
23
45
  expect(AuthValidation_1.AuthValidation.signup(validSignup, false)).toBeUndefined();
24
46
  });
25
47
  it('requires a name', function () {
26
- expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { name: ' ' }), false)).toBe('Please enter your name.');
48
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { name: ' ' }), false)).toEqual({ name: 'Enter your name' });
49
+ });
50
+ it('requires an email when not invited', function () {
51
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { email: '' }), false)).toEqual({ email: 'Enter your email' });
27
52
  });
28
53
  it('requires a valid email when not invited', function () {
29
- expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { email: 'not-an-email' }), false)).toBe('Please enter a valid email address.');
54
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { email: 'not-an-email' }), false)).toEqual({
55
+ email: 'Enter a valid email address',
56
+ });
30
57
  });
31
58
  it('skips the email check for invited users (the invite token carries the email)', function () {
32
59
  expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { email: '' }), true)).toBeUndefined();
33
60
  });
34
61
  it('requires a password', function () {
35
- expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { password: '', confirmPassword: '' }), false)).toBe('Please enter a password.');
62
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { password: '', confirmPassword: '' }), false)).toEqual({
63
+ password: 'Enter a password',
64
+ });
36
65
  });
37
- it('rejects a mismatched password confirmation', function () {
38
- expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { confirmPassword: 'different' }), false)).toBe('Passwords do not match.');
66
+ it('marks a mismatched password confirmation on the confirmation', function () {
67
+ expect(AuthValidation_1.AuthValidation.signup(__assign(__assign({}, validSignup), { confirmPassword: 'different' }), false)).toEqual({
68
+ confirmPassword: 'Passwords do not match',
69
+ });
39
70
  });
40
71
  });
41
72
  describe('AuthValidation.passwordReset', function () {
@@ -43,10 +74,14 @@ describe('AuthValidation.passwordReset', function () {
43
74
  expect(AuthValidation_1.AuthValidation.passwordReset({ newPassword: 'hunter22', confirmPassword: 'hunter22' })).toBeUndefined();
44
75
  });
45
76
  it('requires a new password', function () {
46
- expect(AuthValidation_1.AuthValidation.passwordReset({ newPassword: '', confirmPassword: '' })).toBe('Please enter a new password.');
77
+ expect(AuthValidation_1.AuthValidation.passwordReset({ newPassword: '', confirmPassword: '' })).toEqual({
78
+ newPassword: 'Enter a new password',
79
+ });
47
80
  });
48
- it('rejects a mismatched confirmation', function () {
49
- expect(AuthValidation_1.AuthValidation.passwordReset({ newPassword: 'hunter22', confirmPassword: 'hunter23' })).toBe('Passwords do not match.');
81
+ it('marks a mismatched confirmation on the confirmation', function () {
82
+ expect(AuthValidation_1.AuthValidation.passwordReset({ newPassword: 'hunter22', confirmPassword: 'hunter23' })).toEqual({
83
+ confirmPassword: 'Passwords do not match',
84
+ });
50
85
  });
51
86
  });
52
87
  //# sourceMappingURL=authValidation.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authValidation.test.js","sourceRoot":"","sources":["../../test/authValidation.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6DAA4D;AAE5D,IAAM,WAAW,GAAG;IAClB,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,iBAAiB;IACxB,QAAQ,EAAE,UAAU;IACpB,eAAe,EAAE,UAAU;CAC5B,CAAC;AAEF,QAAQ,CAAC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AAC,CAAC,CAAC,aAAa,EAAE,CAAC;IACjH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE;QAC5B,MAAM,CAAC,+BAAc,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YACrF,WAAW,EAAE,sBAAsB;SACpC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qDAAqD,EAAE;QACxD,MAAM,CAAC,+BAAc,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;YACrG,eAAe,EAAE,wBAAwB;SAC1C,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ declare global {
2
+ var IS_REACT_ACT_ENVIRONMENT: boolean;
3
+ }
4
+ export {};
5
+ //# sourceMappingURL=forgotPasswordAnswer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forgotPasswordAnswer.test.d.ts","sourceRoot":"","sources":["../../test/forgotPasswordAnswer.test.tsx"],"names":[],"mappings":"AAaA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,wBAAwB,EAAE,OAAO,CAAC;CACvC"}
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ /**
43
+ * @jest-environment jsdom
44
+ * @jest-environment-options {"customExportConditions": ["node", "node-addons"]}
45
+ *
46
+ * What a person sees after asking for a reset link: the door's own answer — the one sentence it
47
+ * gives for every address, with an account or without, throttled or not — never a claim that a
48
+ * mail was sent (the page cannot know, and must not seem to).
49
+ */
50
+ var react_1 = __importDefault(require("react"));
51
+ var client_1 = require("react-dom/client");
52
+ var test_utils_1 = require("react-dom/test-utils");
53
+ var ForgotPassword_1 = require("../src/pages/ForgotPassword");
54
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
55
+ var ONE_ANSWER = 'If that address has an account, a reset link is on its way.';
56
+ var container;
57
+ var root;
58
+ beforeEach(function () {
59
+ container = document.createElement('div');
60
+ document.body.appendChild(container);
61
+ root = (0, client_1.createRoot)(container);
62
+ });
63
+ afterEach(function () { return __awaiter(void 0, void 0, void 0, function () {
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0: return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
67
+ return [2 /*return*/, root.unmount()];
68
+ }); }); })];
69
+ case 1:
70
+ _a.sent();
71
+ container.remove();
72
+ delete global.fetch;
73
+ return [2 /*return*/];
74
+ }
75
+ });
76
+ }); });
77
+ function type(input, value) {
78
+ var _a;
79
+ var setValue = (_a = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')) === null || _a === void 0 ? void 0 : _a.set;
80
+ setValue === null || setValue === void 0 ? void 0 : setValue.call(input, value);
81
+ input.dispatchEvent(new Event('input', { bubbles: true }));
82
+ }
83
+ function askForALink(email) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var ForgotPassword;
86
+ var _this = this;
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
89
+ case 0:
90
+ ForgotPassword = ForgotPassword_1.forgotPasswordPage.component;
91
+ return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(_this, void 0, void 0, function () {
92
+ return __generator(this, function (_a) {
93
+ root.render(react_1.default.createElement(ForgotPassword, { urlParams: {} }));
94
+ return [2 /*return*/];
95
+ });
96
+ }); })];
97
+ case 1:
98
+ _a.sent();
99
+ return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(_this, void 0, void 0, function () {
100
+ return __generator(this, function (_a) {
101
+ type(document.getElementById('auth-field-Email'), email);
102
+ return [2 /*return*/];
103
+ });
104
+ }); })];
105
+ case 2:
106
+ _a.sent();
107
+ return [4 /*yield*/, (0, test_utils_1.act)(function () { return __awaiter(_this, void 0, void 0, function () {
108
+ var _a;
109
+ return __generator(this, function (_b) {
110
+ (_a = container.querySelector('form')) === null || _a === void 0 ? void 0 : _a.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
111
+ return [2 /*return*/];
112
+ });
113
+ }); })];
114
+ case 3:
115
+ _a.sent();
116
+ return [2 /*return*/];
117
+ }
118
+ });
119
+ });
120
+ }
121
+ describe('forgot password — the answer shown', function () {
122
+ it("shows the door's one sentence, never a claim that a mail was sent", function () { return __awaiter(void 0, void 0, void 0, function () {
123
+ return __generator(this, function (_a) {
124
+ switch (_a.label) {
125
+ case 0:
126
+ global.fetch = jest.fn().mockResolvedValue({
127
+ status: 200,
128
+ statusText: 'OK',
129
+ json: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
130
+ return [2 /*return*/, ({ message: ONE_ANSWER })];
131
+ }); }); },
132
+ });
133
+ return [4 /*yield*/, askForALink('ada@example.com')];
134
+ case 1:
135
+ _a.sent();
136
+ expect(document.body.textContent).toContain(ONE_ANSWER);
137
+ expect(document.body.textContent).not.toContain('We sent an email');
138
+ return [2 /*return*/];
139
+ }
140
+ });
141
+ }); });
142
+ });
143
+ //# sourceMappingURL=forgotPasswordAnswer.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forgotPasswordAnswer.test.js","sourceRoot":"","sources":["../../test/forgotPasswordAnswer.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;GAOG;AACH,g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,CAAC,EAAA;;oBAFF,SAEE,CAAC;oBACH,qBAAM,IAAA,gBAAG,EAAC;;gCACR,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,kBAAkB,CAAqB,EAAE,KAAK,CAAC,CAAC;;;6BAC9E,CAAC,EAAA;;oBAFF,SAEE,CAAC;oBACH,qBAAM,IAAA,gBAAG,EAAC;;;gCACR,MAAA,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,0CAAE,aAAa,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;;;6BAC1G,CAAC,EAAA;;oBAFF,SAEE,CAAC;;;;;CACJ;AAED,QAAQ,CAAC,oCAAoC,EAAE;IAC7C,EAAE,CAAC,mEAAmE,EAAE;;;;oBACrE,MAAc,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;wBAClD,MAAM,EAAE,GAAG;wBACX,UAAU,EAAE,IAAI;wBAChB,IAAI,EAAE;4BAAY,sBAAA,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,EAAA;iCAAA;qBAC5C,CAAC,CAAC;oBAEH,qBAAM,WAAW,CAAC,iBAAiB,CAAC,EAAA;;oBAApC,SAAoC,CAAC;oBAErC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;oBACxD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;;;;SACrE,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/index.ts CHANGED
@@ -10,3 +10,7 @@ export * from './src/auth/AuthTextField';
10
10
  export * from './src/auth/AuthButton';
11
11
  export * from './src/auth/AuthFormError';
12
12
  export * from './src/auth/AuthMessagePanel';
13
+ // The form reader the pages above use at submit (uncontrolled fields; the values read from the
14
+ // form itself) — exported so a consumer page fixes the same class the same way, not by hand.
15
+ export * from './src/auth/AuthFormFields';
16
+ export type { AuthFieldErrors } from './src/auth/AuthValidation';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/user-ui",
3
- "version": "1.11.1",
3
+ "version": "1.11.3",
4
4
  "description": "User ui components",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -56,5 +56,5 @@
56
56
  },
57
57
  "main": "./dist/generated/index.js",
58
58
  "types": "./dist/generated/index.d.ts",
59
- "gitHead": "ae04a205d52875798ff9320f51d934f7f131b646"
59
+ "gitHead": "ae97c22e42cbb471bddf3f0ddc08f93fad4be375"
60
60
  }
@@ -46,7 +46,11 @@ export class AuthApi {
46
46
  }
47
47
  }
48
48
 
49
- async initiatePasswordReset(email: string): Promise<void> {
49
+ /**
50
+ * Resolves with the door's answer — the one sentence it gives for every address, with an
51
+ * account or without — for the page to show as it is.
52
+ */
53
+ async initiatePasswordReset(email: string): Promise<string> {
50
54
  const response = await fetch(routes.initiatePasswordReset.path, {
51
55
  method: routes.initiatePasswordReset.method,
52
56
  body: JSON.stringify({ email }),
@@ -62,6 +66,8 @@ export class AuthApi {
62
66
  if (body.error) {
63
67
  throw new Error(`Failed to send the reset email. Please try again.`);
64
68
  }
69
+
70
+ return body.message;
65
71
  }
66
72
 
67
73
  /**
@@ -0,0 +1,35 @@
1
+ import { AuthFieldErrors } from './AuthValidation';
2
+
3
+ /**
4
+ * Reads an auth form's fields from the form itself when it submits.
5
+ *
6
+ * A password manager, the platform's autofill service or an input method can write a field's
7
+ * value without the `input` event React listens for: the field looks filled while component
8
+ * state is still empty, and a controlled field's next re-render (the focus ring moving as the
9
+ * person taps the button is enough) writes that empty state back over the value. So the fields
10
+ * a person fills are uncontrolled — each carries a `name` and owns its value in the DOM — and
11
+ * the submit handler reads them here. There is no second copy of a value to fall out of step.
12
+ */
13
+ export class AuthFormFields {
14
+ /** The named fields' current values; '' for a name the form does not carry. */
15
+ static read<F extends string>(form: HTMLFormElement, names: readonly F[]): Record<F, string> {
16
+ const data = new FormData(form);
17
+ const values = {} as Record<F, string>;
18
+ for (const name of names) {
19
+ const value = data.get(name);
20
+ values[name] = typeof value === 'string' ? value : '';
21
+ }
22
+ return values;
23
+ }
24
+
25
+ /** Focuses the first field, in document order, that carries an error (the keyboard opens there). */
26
+ static focusFirstInvalid<F extends string>(form: HTMLFormElement, errors: AuthFieldErrors<F>) {
27
+ for (let index = 0; index < form.elements.length; index++) {
28
+ const element = form.elements[index] as HTMLInputElement;
29
+ if (element.name && errors[element.name as F]) {
30
+ element.focus();
31
+ return;
32
+ }
33
+ }
34
+ }
35
+ }
@@ -5,9 +5,21 @@ import VisibilityOff from '@mui/icons-material/VisibilityOff';
5
5
 
6
6
  export interface AuthTextFieldProps {
7
7
  label: string;
8
- value: string;
9
- /** Omitted for read-only fields. */
8
+ /**
9
+ * The form-field name the page reads the value by when the form submits
10
+ * (`AuthFormFields.read`). A field the person fills is uncontrolled — it carries `name` (and an
11
+ * optional `defaultValue`) and no `value` — so whatever writes into it (typing, a password
12
+ * manager, the platform's autofill) is exactly what the submit reads.
13
+ */
14
+ name?: string;
15
+ /** Controlled value — for a field the page itself fills (e.g. a read-only identity). */
16
+ value?: string;
17
+ /** Initial value of an uncontrolled field. */
18
+ defaultValue?: string;
19
+ /** Called on every edit the browser announces; an uncontrolled field's value stays in the DOM. */
10
20
  onChange?: (value: string) => void;
21
+ /** Marks the field invalid and shows this message under it (in place of `helperText`). */
22
+ error?: string;
11
23
  /** Renders a reveal toggle and masks input until toggled. */
12
24
  password?: boolean;
13
25
  /**
@@ -36,8 +48,11 @@ export interface AuthTextFieldProps {
36
48
  export function AuthTextField(props: AuthTextFieldProps) {
37
49
  const {
38
50
  label,
51
+ name,
39
52
  value,
53
+ defaultValue,
40
54
  onChange,
55
+ error,
41
56
  password,
42
57
  readOnly,
43
58
  autoComplete,
@@ -61,7 +76,9 @@ export function AuthTextField(props: AuthTextFieldProps) {
61
76
  <TextField
62
77
  id={`auth-field-${label}`}
63
78
  fullWidth
79
+ name={name}
64
80
  value={value}
81
+ defaultValue={defaultValue}
65
82
  onChange={(event) => onChange?.(event.target.value)}
66
83
  type={password && !revealed ? 'password' : password ? 'text' : type || 'text'}
67
84
  autoComplete={autoComplete}
@@ -69,7 +86,8 @@ export function AuthTextField(props: AuthTextFieldProps) {
69
86
  disabled={disabled}
70
87
  multiline={!!multilineRows}
71
88
  rows={multilineRows}
72
- helperText={helperText}
89
+ error={!!error}
90
+ helperText={error ?? helperText}
73
91
  InputProps={{
74
92
  readOnly,
75
93
  endAdornment: password ? (
@@ -98,6 +116,8 @@ export function AuthTextField(props: AuthTextFieldProps) {
98
116
  '& fieldset': { borderColor: 'divider' },
99
117
  '&:hover fieldset': { borderColor: readOnly ? 'divider' : 'text.disabled' },
100
118
  '&.Mui-focused fieldset': { borderColor: 'primary.main', borderWidth: '1.5px' },
119
+ // A marked field keeps its error border while focused (the person is fixing it).
120
+ '&.Mui-error fieldset': { borderColor: 'error.main' },
101
121
  },
102
122
  }}
103
123
  />
@@ -1,39 +1,78 @@
1
1
  import { emailRegex } from '@proteinjs/util';
2
2
 
3
+ /** A user-readable message per invalid field, keyed by the field's form name. */
4
+ export type AuthFieldErrors<F extends string> = { [K in F]?: string };
5
+
3
6
  /**
4
- * Client-side validation for the auth flows. Each method returns a user-readable
5
- * error message, or undefined when the input is valid.
7
+ * Client-side validation for the auth flows. Each method returns the invalid fields with a
8
+ * user-readable message each (the page marks those fields), or undefined when the input is
9
+ * valid. A blank field is refused here, in the page, so a real form never sends one.
6
10
  */
7
11
  export class AuthValidation {
12
+ static login(fields: { email: string; password: string }): AuthFieldErrors<'email' | 'password'> | undefined {
13
+ const errors: AuthFieldErrors<'email' | 'password'> = {};
14
+ if (!fields.email.trim()) {
15
+ errors.email = 'Enter your email';
16
+ }
17
+
18
+ if (!fields.password) {
19
+ errors.password = 'Enter your password';
20
+ }
21
+
22
+ return AuthValidation.outcome(errors);
23
+ }
24
+
25
+ static forgotPassword(fields: { email: string }): AuthFieldErrors<'email'> | undefined {
26
+ const errors: AuthFieldErrors<'email'> = {};
27
+ if (!fields.email.trim()) {
28
+ errors.email = 'Enter your email';
29
+ }
30
+
31
+ return AuthValidation.outcome(errors);
32
+ }
33
+
8
34
  /** @param invited invited users don't enter an email (the invite token carries it) */
9
35
  static signup(
10
36
  fields: { name: string; email: string; password: string; confirmPassword: string },
11
37
  invited: boolean
12
- ): string | undefined {
38
+ ): AuthFieldErrors<'name' | 'email' | 'password' | 'confirmPassword'> | undefined {
39
+ const errors: AuthFieldErrors<'name' | 'email' | 'password' | 'confirmPassword'> = {};
13
40
  if (!fields.name.trim()) {
14
- return 'Please enter your name.';
41
+ errors.name = 'Enter your name';
15
42
  }
16
43
 
17
- if (!invited && !emailRegex.test(fields.email.trim())) {
18
- return 'Please enter a valid email address.';
44
+ if (!invited) {
45
+ if (!fields.email.trim()) {
46
+ errors.email = 'Enter your email';
47
+ } else if (!emailRegex.test(fields.email.trim())) {
48
+ errors.email = 'Enter a valid email address';
49
+ }
19
50
  }
20
51
 
21
52
  if (!fields.password) {
22
- return 'Please enter a password.';
53
+ errors.password = 'Enter a password';
54
+ } else if (fields.password !== fields.confirmPassword) {
55
+ errors.confirmPassword = 'Passwords do not match';
23
56
  }
24
57
 
25
- if (fields.password !== fields.confirmPassword) {
26
- return 'Passwords do not match.';
27
- }
58
+ return AuthValidation.outcome(errors);
28
59
  }
29
60
 
30
- static passwordReset(fields: { newPassword: string; confirmPassword: string }): string | undefined {
61
+ static passwordReset(fields: {
62
+ newPassword: string;
63
+ confirmPassword: string;
64
+ }): AuthFieldErrors<'newPassword' | 'confirmPassword'> | undefined {
65
+ const errors: AuthFieldErrors<'newPassword' | 'confirmPassword'> = {};
31
66
  if (!fields.newPassword) {
32
- return 'Please enter a new password.';
67
+ errors.newPassword = 'Enter a new password';
68
+ } else if (fields.newPassword !== fields.confirmPassword) {
69
+ errors.confirmPassword = 'Passwords do not match';
33
70
  }
34
71
 
35
- if (fields.newPassword !== fields.confirmPassword) {
36
- return 'Passwords do not match.';
37
- }
72
+ return AuthValidation.outcome(errors);
73
+ }
74
+
75
+ private static outcome<F extends string>(errors: AuthFieldErrors<F>): AuthFieldErrors<F> | undefined {
76
+ return Object.keys(errors).length > 0 ? errors : undefined;
38
77
  }
39
78
  }
@@ -9,31 +9,44 @@ import { AuthButton } from '../auth/AuthButton';
9
9
  import { AuthFormError } from '../auth/AuthFormError';
10
10
  import { AuthMessagePanel } from '../auth/AuthMessagePanel';
11
11
  import { AuthApi } from '../auth/AuthApi';
12
+ import { AuthFormFields } from '../auth/AuthFormFields';
13
+ import { AuthFieldErrors, AuthValidation } from '../auth/AuthValidation';
12
14
 
13
15
  const ForgotPasswordComponent: React.FC = () => {
14
- const [email, setEmail] = useState('');
16
+ const [fieldErrors, setFieldErrors] = useState<AuthFieldErrors<'email'>>({});
15
17
  const [error, setError] = useState<string | undefined>();
16
18
  const [busy, setBusy] = useState(false);
17
- const [sent, setSent] = useState(false);
19
+ const [answer, setAnswer] = useState<string | undefined>();
18
20
 
19
- const onSubmit = async (event: React.FormEvent) => {
21
+ const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
20
22
  event.preventDefault();
23
+ // Read from the form at submit, like login: an autofilled email may be in the DOM only.
24
+ const form = event.currentTarget;
25
+ const { email } = AuthFormFields.read(form, ['email'] as const);
26
+ const invalid = AuthValidation.forgotPassword({ email });
27
+ setFieldErrors(invalid ?? {});
28
+ if (invalid) {
29
+ AuthFormFields.focusFirstInvalid(form, invalid);
30
+ return;
31
+ }
32
+
21
33
  setError(undefined);
22
34
  setBusy(true);
23
35
  try {
24
- await new AuthApi().initiatePasswordReset(email);
25
- setSent(true);
36
+ setAnswer(await new AuthApi().initiatePasswordReset(email.trim()));
26
37
  } catch (error: any) {
27
38
  setError(error.message);
28
39
  setBusy(false);
29
40
  }
30
41
  };
31
42
 
32
- if (sent) {
43
+ // The door's own sentence: it gives the same one for every address, so the page never claims
44
+ // a mail was sent (it cannot know, and must not seem to).
45
+ if (answer) {
33
46
  return (
34
47
  <AuthMessagePanel
35
48
  title='Check your email'
36
- body='We sent an email with a link to reset your password.'
49
+ body={answer}
37
50
  actionName='Back to log in'
38
51
  actionHref={`/${uiRoutes.auth.login}`}
39
52
  />
@@ -54,8 +67,9 @@ const ForgotPasswordComponent: React.FC = () => {
54
67
  stored username here too. */}
55
68
  <AuthTextField
56
69
  label='Email'
57
- value={email}
58
- onChange={setEmail}
70
+ name='email'
71
+ onChange={() => setFieldErrors((errors) => (errors.email ? {} : errors))}
72
+ error={fieldErrors.email}
59
73
  type='email'
60
74
  autoComplete='username'
61
75
  disabled={busy}
@@ -8,19 +8,36 @@ import { AuthTextField } from '../auth/AuthTextField';
8
8
  import { AuthButton } from '../auth/AuthButton';
9
9
  import { AuthFormError } from '../auth/AuthFormError';
10
10
  import { AuthApi } from '../auth/AuthApi';
11
+ import { AuthFormFields } from '../auth/AuthFormFields';
12
+ import { AuthFieldErrors, AuthValidation } from '../auth/AuthValidation';
13
+
14
+ type LoginField = 'email' | 'password';
11
15
 
12
16
  const LoginComponent: React.FC = () => {
13
- const [email, setEmail] = useState('');
14
- const [password, setPassword] = useState('');
17
+ const [fieldErrors, setFieldErrors] = useState<AuthFieldErrors<LoginField>>({});
15
18
  const [error, setError] = useState<string | undefined>();
16
19
  const [busy, setBusy] = useState(false);
17
20
 
18
- const onSubmit = async (event: React.FormEvent) => {
21
+ const clearFieldError = (name: LoginField) =>
22
+ setFieldErrors((errors) => (errors[name] ? { ...errors, [name]: undefined } : errors));
23
+
24
+ const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
19
25
  event.preventDefault();
26
+ // The fields' values as they are NOW, read from the form — a password manager or autofill
27
+ // that wrote a field without an input event is only in the DOM (AuthFormFields).
28
+ const form = event.currentTarget;
29
+ const { email, password } = AuthFormFields.read(form, ['email', 'password'] as const);
30
+ const invalid = AuthValidation.login({ email, password });
31
+ setFieldErrors(invalid ?? {});
32
+ if (invalid) {
33
+ AuthFormFields.focusFirstInvalid(form, invalid);
34
+ return;
35
+ }
36
+
20
37
  setError(undefined);
21
38
  setBusy(true);
22
39
  try {
23
- await new AuthApi().login(email, password);
40
+ await new AuthApi().login(email.trim(), password);
24
41
  window.location.href = '/';
25
42
  } catch (error: any) {
26
43
  setError(error.message);
@@ -39,16 +56,18 @@ const LoginComponent: React.FC = () => {
39
56
  fill from the saved login; type='email' still gives the email keyboard. */}
40
57
  <AuthTextField
41
58
  label='Email'
42
- value={email}
43
- onChange={setEmail}
59
+ name='email'
60
+ onChange={() => clearFieldError('email')}
61
+ error={fieldErrors.email}
44
62
  type='email'
45
63
  autoComplete='username'
46
64
  disabled={busy}
47
65
  />
48
66
  <AuthTextField
49
67
  label='Password'
50
- value={password}
51
- onChange={setPassword}
68
+ name='password'
69
+ onChange={() => clearFieldError('password')}
70
+ error={fieldErrors.password}
52
71
  password
53
72
  autoComplete='current-password'
54
73
  disabled={busy}