@proteinjs/user-ui 1.0.12 → 1.0.14
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/.eslintrc.js +20 -0
- package/.prettierignore +4 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +15 -2
- package/LICENSE +21 -0
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/src/AuthenticatedPageContainer.d.ts.map +1 -1
- package/dist/src/AuthenticatedPageContainer.js +11 -7
- package/dist/src/AuthenticatedPageContainer.js.map +1 -1
- package/dist/src/pages/Login.d.ts.map +1 -1
- package/dist/src/pages/Login.js +12 -10
- package/dist/src/pages/Login.js.map +1 -1
- package/dist/src/pages/Signup.d.ts.map +1 -1
- package/dist/src/pages/Signup.js +14 -12
- package/dist/src/pages/Signup.js.map +1 -1
- package/generated/index.ts +5 -8
- package/index.ts +1 -1
- package/jest.config.js +8 -17
- package/package.json +10 -4
- package/src/AuthenticatedPageContainer.tsx +40 -36
- package/src/pages/Login.tsx +58 -56
- package/src/pages/Signup.tsx +66 -64
- package/tsconfig.json +17 -17
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'prettier'],
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
plugins: ['@typescript-eslint', 'prettier'],
|
|
5
|
+
root: true,
|
|
6
|
+
ignorePatterns: ['**/dist/*', '**/node_modules/*', '*.md'],
|
|
7
|
+
|
|
8
|
+
rules: {
|
|
9
|
+
'prettier/prettier': ['warn'],
|
|
10
|
+
curly: ['warn'],
|
|
11
|
+
'eol-last': ['warn', 'always'],
|
|
12
|
+
'keyword-spacing': ['warn', { before: true }],
|
|
13
|
+
'no-undef': 'off',
|
|
14
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
15
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
16
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
17
|
+
'@typescript-eslint/prefer-as-const': 'off',
|
|
18
|
+
'@typescript-eslint/ban-types': 'off',
|
|
19
|
+
},
|
|
20
|
+
};
|
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -3,13 +3,26 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [1.0.
|
|
6
|
+
## [1.0.14](https://github.com/proteinjs/user/compare/@proteinjs/user-ui@1.0.13...@proteinjs/user-ui@1.0.14) (2024-05-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* add .md file type to lint ignore files ([372c51f](https://github.com/proteinjs/user/commit/372c51fdc0a48c8559321862e3b7cebe05e4955d))
|
|
12
|
+
|
|
7
13
|
|
|
8
|
-
**Note:** Version bump only for package @proteinjs/user-ui
|
|
9
14
|
|
|
10
15
|
|
|
11
16
|
|
|
17
|
+
## [1.0.13](https://github.com/proteinjs/user/compare/@proteinjs/user-ui@1.0.12...@proteinjs/user-ui@1.0.13) (2024-05-10)
|
|
12
18
|
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
- add linting and lint all files ([71defcd](https://github.com/proteinjs/user/commit/71defcd78dc479d2eef1f624c746c879f4e31daa))
|
|
22
|
+
|
|
23
|
+
## [1.0.11](https://github.com/proteinjs/user/compare/@proteinjs/user-ui@1.0.10...@proteinjs/user-ui@1.0.11) (2024-05-09)
|
|
24
|
+
|
|
25
|
+
**Note:** Version bump only for package @proteinjs/user-ui
|
|
13
26
|
|
|
14
27
|
## 1.0.1 (2024-04-19)
|
|
15
28
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Brent Bahry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/generated/index.js
CHANGED
|
@@ -23,7 +23,7 @@ require("moment");
|
|
|
23
23
|
require("react");
|
|
24
24
|
require("react-dom");
|
|
25
25
|
/** Generate Source Graph */
|
|
26
|
-
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"/Omit\"},{\"v\":\"@proteinjs/user-ui/loginPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"loginPage\",\"filePath\":\"/
|
|
26
|
+
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"/Omit\"},{\"v\":\"@proteinjs/user-ui/loginPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"loginPage\",\"filePath\":\"/home/runner/work/user/user/packages/ui/src/pages/Login.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/loginPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/ui/Page\"},{\"v\":\"@proteinjs/user-ui/signupPage\",\"value\":{\"packageName\":\"@proteinjs/user-ui\",\"name\":\"signupPage\",\"filePath\":\"/home/runner/work/user/user/packages/ui/src/pages/Signup.tsx\",\"qualifiedName\":\"@proteinjs/user-ui/signupPage\",\"type\":{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/ui\",\"name\":\"Page\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/ui/Page\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}}],\"edges\":[{\"v\":\"@proteinjs/user-ui/loginPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-ui/signupPage\",\"w\":\"@proteinjs/ui/Page\",\"value\":\"has type\"}]}";
|
|
27
27
|
/** Generate Source Links */
|
|
28
28
|
var Login_1 = require("../src/pages/Login");
|
|
29
29
|
var Signup_1 = require("../src/pages/Signup");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,iCAA+B;AAC/B,iCAA+B;AAC/B,yBAAuB;AACvB,2BAAyB;AACzB,kBAAgB;AAChB,iBAAe;AACf,qBAAmB;AAGnB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,iCAA+B;AAC/B,iCAA+B;AAC/B,yBAAuB;AACvB,2BAAyB;AACzB,kBAAgB;AAChB,iBAAe;AACf,qBAAmB;AAGnB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,yiDAAyiD,CAAC;AAG9jD,4BAA4B;AAE5B,4CAA+C;AAC/C,8CAAiD;AAEjD,IAAM,WAAW,GAAG;IACnB,8BAA8B,EAAE,iBAAS;IACzC,+BAA+B,EAAE,mBAAU;CAC3C,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticatedPageContainer.d.ts","sourceRoot":"","sources":["../../src/AuthenticatedPageContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAuB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIxE,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;AAE/E,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,
|
|
1
|
+
{"version":3,"file":"AuthenticatedPageContainer.d.ts","sourceRoot":"","sources":["../../src/AuthenticatedPageContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAuB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIxE,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;AAE/E,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,qBA6ChF"}
|
|
@@ -74,12 +74,15 @@ function AuthenticatedPageContainer(props) {
|
|
|
74
74
|
isLoggedIn: isLoggedIn,
|
|
75
75
|
canViewPage: function (page) {
|
|
76
76
|
var _a, _b, _c, _d;
|
|
77
|
-
if ((_a = page.auth) === null || _a === void 0 ? void 0 : _a.public)
|
|
77
|
+
if ((_a = page.auth) === null || _a === void 0 ? void 0 : _a.public) {
|
|
78
78
|
return true;
|
|
79
|
-
|
|
79
|
+
}
|
|
80
|
+
if ((_b = page.auth) === null || _b === void 0 ? void 0 : _b.allUsers) {
|
|
80
81
|
return user_1.UserAuth.isLoggedIn();
|
|
81
|
-
|
|
82
|
+
}
|
|
83
|
+
if (!((_c = page.auth) === null || _c === void 0 ? void 0 : _c.roles)) {
|
|
82
84
|
return user_1.UserAuth.hasRole('admin');
|
|
85
|
+
}
|
|
83
86
|
return user_1.UserAuth.hasRoles((_d = page.auth) === null || _d === void 0 ? void 0 : _d.roles);
|
|
84
87
|
},
|
|
85
88
|
login: Login_1.loginPath,
|
|
@@ -92,19 +95,20 @@ function AuthenticatedPageContainer(props) {
|
|
|
92
95
|
redirect: 'follow',
|
|
93
96
|
credentials: 'same-origin',
|
|
94
97
|
headers: {
|
|
95
|
-
'Content-Type': 'application/json'
|
|
96
|
-
}
|
|
98
|
+
'Content-Type': 'application/json',
|
|
99
|
+
},
|
|
97
100
|
})];
|
|
98
101
|
case 1:
|
|
99
102
|
response = _a.sent();
|
|
100
|
-
if (response.status != 200)
|
|
103
|
+
if (response.status != 200) {
|
|
101
104
|
throw new Error("Failed to log out");
|
|
105
|
+
}
|
|
102
106
|
new user_1.UserRepo().setUser(user_1.guestUser);
|
|
103
107
|
setIsLoggedIn(false);
|
|
104
108
|
return [2 /*return*/, Login_1.loginPath];
|
|
105
109
|
}
|
|
106
110
|
});
|
|
107
|
-
}); }
|
|
111
|
+
}); },
|
|
108
112
|
} }, other)));
|
|
109
113
|
}
|
|
110
114
|
exports.AuthenticatedPageContainer = AuthenticatedPageContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticatedPageContainer.js","sourceRoot":"","sources":["../../src/AuthenticatedPageContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,oCAAwE;AACxE,wCAAwE;AACxE,uCAA0C;AAI1C,SAAgB,0BAA0B,CAAC,KAAsC;IAAjF,
|
|
1
|
+
{"version":3,"file":"AuthenticatedPageContainer.js","sourceRoot":"","sources":["../../src/AuthenticatedPageContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,oCAAwE;AACxE,wCAAwE;AACxE,uCAA0C;AAI1C,SAAgB,0BAA0B,CAAC,KAAsC;IAAjF,iBA6CC;IA5CC,IAAW,KAAK,UAAK,KAAK,EAApB,EAAY,CAAQ,CAAC;IACrB,IAAA,KAA8B,eAAK,CAAC,QAAQ,CAAC,eAAQ,CAAC,UAAU,EAAE,CAAC,EAAlE,UAAU,QAAA,EAAE,aAAa,QAAyC,CAAC;IAE1E,OAAO,CACL,8BAAC,kBAAa,aACZ,IAAI,EAAE;YACJ,UAAU,YAAA;YACV,WAAW,EAAE,UAAC,IAAU;;gBACtB,IAAI,MAAA,IAAI,CAAC,IAAI,0CAAE,MAAM,EAAE;oBACrB,OAAO,IAAI,CAAC;iBACb;gBAED,IAAI,MAAA,IAAI,CAAC,IAAI,0CAAE,QAAQ,EAAE;oBACvB,OAAO,eAAQ,CAAC,UAAU,EAAE,CAAC;iBAC9B;gBAED,IAAI,CAAC,CAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAA,EAAE;oBACrB,OAAO,eAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;iBAClC;gBAED,OAAO,eAAQ,CAAC,QAAQ,CAAC,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAC,CAAC;YAC7C,CAAC;YACD,KAAK,EAAE,iBAAS;YAChB,MAAM,EAAE;;;;gCACW,qBAAM,KAAK,CAAC,aAAM,CAAC,MAAM,CAAC,IAAI,EAAE;gCAC/C,MAAM,EAAE,aAAM,CAAC,MAAM,CAAC,MAAM;gCAC5B,QAAQ,EAAE,QAAQ;gCAClB,WAAW,EAAE,aAAa;gCAC1B,OAAO,EAAE;oCACP,cAAc,EAAE,kBAAkB;iCACnC;6BACF,CAAC,EAAA;;4BAPI,QAAQ,GAAG,SAOf;4BACF,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE;gCAC1B,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;6BACtC;4BAED,IAAI,eAAQ,EAAE,CAAC,OAAO,CAAC,gBAAS,CAAC,CAAC;4BAClC,aAAa,CAAC,KAAK,CAAC,CAAC;4BACrB,sBAAO,iBAAS,EAAC;;;iBAClB;SACF,IACG,KAAK,EACT,CACH,CAAC;AACJ,CAAC;AA7CD,gEA6CC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Login.d.ts","sourceRoot":"","sources":["../../../src/pages/Login.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAA+D,MAAM,eAAe,CAAC;AAGlG,eAAO,MAAM,SAAS,UAAU,CAAC;AACjC,eAAO,MAAM,SAAS,EAAE,IAgBvB,
|
|
1
|
+
{"version":3,"file":"Login.d.ts","sourceRoot":"","sources":["../../../src/pages/Login.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAA+D,MAAM,eAAe,CAAC;AAGlG,eAAO,MAAM,SAAS,UAAU,CAAC;AACjC,eAAO,MAAM,SAAS,EAAE,IAgBvB,CAAC"}
|
package/dist/src/pages/Login.js
CHANGED
|
@@ -66,18 +66,18 @@ exports.loginPage = {
|
|
|
66
66
|
public: true,
|
|
67
67
|
},
|
|
68
68
|
component: function () { return (react_1.default.createElement(ui_1.FormPage, null,
|
|
69
|
-
react_1.default.createElement(ui_1.Form, { name: 'Login', createFields: function () { return new LoginFields(); }, fieldLayout: ['email', 'password'], buttons: buttons }))); }
|
|
69
|
+
react_1.default.createElement(ui_1.Form, { name: 'Login', createFields: function () { return new LoginFields(); }, fieldLayout: ['email', 'password'], buttons: buttons }))); },
|
|
70
70
|
};
|
|
71
71
|
var LoginFields = /** @class */ (function (_super) {
|
|
72
72
|
__extends(LoginFields, _super);
|
|
73
73
|
function LoginFields() {
|
|
74
74
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
75
75
|
_this.email = (0, ui_1.textField)({
|
|
76
|
-
name: 'email'
|
|
76
|
+
name: 'email',
|
|
77
77
|
});
|
|
78
78
|
_this.password = (0, ui_1.textField)({
|
|
79
79
|
name: 'password',
|
|
80
|
-
isPassword: true
|
|
80
|
+
isPassword: true,
|
|
81
81
|
});
|
|
82
82
|
return _this;
|
|
83
83
|
}
|
|
@@ -102,28 +102,30 @@ var buttons = {
|
|
|
102
102
|
method: user_1.routes.login.method,
|
|
103
103
|
body: JSON.stringify({
|
|
104
104
|
email: fields.email.field.value,
|
|
105
|
-
password: fields.password.field.value
|
|
105
|
+
password: fields.password.field.value,
|
|
106
106
|
}),
|
|
107
107
|
redirect: 'follow',
|
|
108
108
|
credentials: 'same-origin',
|
|
109
109
|
headers: {
|
|
110
|
-
'Content-Type': 'application/json'
|
|
111
|
-
}
|
|
110
|
+
'Content-Type': 'application/json',
|
|
111
|
+
},
|
|
112
112
|
})];
|
|
113
113
|
case 1:
|
|
114
114
|
response = _a.sent();
|
|
115
|
-
if (response.status != 200)
|
|
115
|
+
if (response.status != 200) {
|
|
116
116
|
throw new Error("Failed to login, error: ".concat(response.statusText));
|
|
117
|
+
}
|
|
117
118
|
return [4 /*yield*/, response.json()];
|
|
118
119
|
case 2:
|
|
119
120
|
body = _a.sent();
|
|
120
|
-
if (body.error)
|
|
121
|
+
if (body.error) {
|
|
121
122
|
throw new Error(body.error);
|
|
123
|
+
}
|
|
122
124
|
window.location.href = '/';
|
|
123
125
|
return [2 /*return*/];
|
|
124
126
|
}
|
|
125
127
|
});
|
|
126
|
-
}); }
|
|
127
|
-
}
|
|
128
|
+
}); },
|
|
129
|
+
},
|
|
128
130
|
};
|
|
129
131
|
//# sourceMappingURL=Login.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Login.js","sourceRoot":"","sources":["../../../src/pages/Login.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,oCAAkG;AAClG,
|
|
1
|
+
{"version":3,"file":"Login.js","sourceRoot":"","sources":["../../../src/pages/Login.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,oCAAkG;AAClG,wCAAyC;AAE5B,QAAA,SAAS,GAAG,OAAO,CAAC;AACpB,QAAA,SAAS,GAAS;IAC7B,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,iBAAS;IACf,IAAI,EAAE;QACJ,MAAM,EAAE,IAAI;KACb;IACD,SAAS,EAAE,cAAM,OAAA,CACf,8BAAC,aAAQ;QACP,8BAAC,SAAI,IACH,IAAI,EAAC,OAAO,EACZ,YAAY,EAAE,cAAM,OAAA,IAAI,WAAW,EAAE,EAAjB,CAAiB,EACrC,WAAW,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,EAClC,OAAO,EAAE,OAAO,GAChB,CACO,CACZ,EATgB,CAShB;CACF,CAAC;AAEF;IAA0B,+BAAM;IAAhC;QAAA,qEAaC;QARC,WAAK,GAAG,IAAA,cAAS,EAAc;YAC7B,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;QAEH,cAAQ,GAAG,IAAA,cAAS,EAAc;YAChC,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;;IACL,CAAC;IAZQ,kBAAM,GAAb;QACE,OAAO,IAAI,WAAW,EAAE,CAAC;IAC3B,CAAC;IAUH,kBAAC;AAAD,CAAC,AAbD,CAA0B,WAAM,GAa/B;AAED,IAAM,OAAO,GAA6B;IACxC,KAAK,EAAE,gBAAW;IAClB,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE;YACL,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,WAAW;SACrB;QACD,OAAO,EAAE,UAAO,MAAmB,EAAE,OAAiC;;;;4BACnD,qBAAM,KAAK,CAAC,aAAM,CAAC,KAAK,CAAC,IAAI,EAAE;4BAC9C,MAAM,EAAE,aAAM,CAAC,KAAK,CAAC,MAAM;4BAC3B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gCACnB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK;gCAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK;6BACtC,CAAC;4BACF,QAAQ,EAAE,QAAQ;4BAClB,WAAW,EAAE,aAAa;4BAC1B,OAAO,EAAE;gCACP,cAAc,EAAE,kBAAkB;6BACnC;yBACF,CAAC,EAAA;;wBAXI,QAAQ,GAAG,SAWf;wBACF,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE;4BAC1B,MAAM,IAAI,KAAK,CAAC,kCAA2B,QAAQ,CAAC,UAAU,CAAE,CAAC,CAAC;yBACnE;wBAEY,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA5B,IAAI,GAAG,SAAqB;wBAClC,IAAI,IAAI,CAAC,KAAK,EAAE;4BACd,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;yBAC7B;wBAED,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,CAAC;;;;aAC5B;KACF;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Signup.d.ts","sourceRoot":"","sources":["../../../src/pages/Signup.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAA+D,MAAM,eAAe,CAAC;AAGlG,eAAO,MAAM,UAAU,EAAE,IAgBxB,
|
|
1
|
+
{"version":3,"file":"Signup.d.ts","sourceRoot":"","sources":["../../../src/pages/Signup.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAA+D,MAAM,eAAe,CAAC;AAGlG,eAAO,MAAM,UAAU,EAAE,IAgBxB,CAAC"}
|
package/dist/src/pages/Signup.js
CHANGED
|
@@ -65,25 +65,25 @@ exports.signupPage = {
|
|
|
65
65
|
public: true,
|
|
66
66
|
},
|
|
67
67
|
component: function () { return (react_1.default.createElement(ui_1.FormPage, null,
|
|
68
|
-
react_1.default.createElement(ui_1.Form, { name: 'Sign Up', createFields: function () { return new SignupFields(); }, fieldLayout: ['name', 'email', 'password', 'confirmPassword'], buttons: buttons }))); }
|
|
68
|
+
react_1.default.createElement(ui_1.Form, { name: 'Sign Up', createFields: function () { return new SignupFields(); }, fieldLayout: ['name', 'email', 'password', 'confirmPassword'], buttons: buttons }))); },
|
|
69
69
|
};
|
|
70
70
|
var SignupFields = /** @class */ (function (_super) {
|
|
71
71
|
__extends(SignupFields, _super);
|
|
72
72
|
function SignupFields() {
|
|
73
73
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
74
74
|
_this.name = (0, ui_1.textField)({
|
|
75
|
-
name: 'name'
|
|
75
|
+
name: 'name',
|
|
76
76
|
});
|
|
77
77
|
_this.email = (0, ui_1.textField)({
|
|
78
|
-
name: 'email'
|
|
78
|
+
name: 'email',
|
|
79
79
|
});
|
|
80
80
|
_this.password = (0, ui_1.textField)({
|
|
81
81
|
name: 'password',
|
|
82
|
-
isPassword: true
|
|
82
|
+
isPassword: true,
|
|
83
83
|
});
|
|
84
84
|
_this.confirmPassword = (0, ui_1.textField)({
|
|
85
85
|
name: 'confirmPassword',
|
|
86
|
-
isPassword: true
|
|
86
|
+
isPassword: true,
|
|
87
87
|
});
|
|
88
88
|
return _this;
|
|
89
89
|
}
|
|
@@ -109,27 +109,29 @@ var buttons = {
|
|
|
109
109
|
body: JSON.stringify({
|
|
110
110
|
name: fields.name.field.value,
|
|
111
111
|
email: fields.email.field.value,
|
|
112
|
-
password: fields.password.field.value
|
|
112
|
+
password: fields.password.field.value,
|
|
113
113
|
}),
|
|
114
114
|
redirect: 'follow',
|
|
115
115
|
credentials: 'same-origin',
|
|
116
116
|
headers: {
|
|
117
|
-
'Content-Type': 'application/json'
|
|
118
|
-
}
|
|
117
|
+
'Content-Type': 'application/json',
|
|
118
|
+
},
|
|
119
119
|
})];
|
|
120
120
|
case 1:
|
|
121
121
|
response = _a.sent();
|
|
122
|
-
if (response.status != 200)
|
|
122
|
+
if (response.status != 200) {
|
|
123
123
|
throw new Error("Failed to signup, error: ".concat(response.statusText));
|
|
124
|
+
}
|
|
124
125
|
return [4 /*yield*/, response.json()];
|
|
125
126
|
case 2:
|
|
126
127
|
body = _a.sent();
|
|
127
|
-
if (body.error)
|
|
128
|
+
if (body.error) {
|
|
128
129
|
throw new Error(body.error);
|
|
130
|
+
}
|
|
129
131
|
return [2 /*return*/, "Successfully created your account! Please check your email for an email confirmation."];
|
|
130
132
|
}
|
|
131
133
|
});
|
|
132
|
-
}); }
|
|
133
|
-
}
|
|
134
|
+
}); },
|
|
135
|
+
},
|
|
134
136
|
};
|
|
135
137
|
//# sourceMappingURL=Signup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Signup.js","sourceRoot":"","sources":["../../../src/pages/Signup.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,oCAAkG;AAClG,
|
|
1
|
+
{"version":3,"file":"Signup.js","sourceRoot":"","sources":["../../../src/pages/Signup.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,oCAAkG;AAClG,wCAAyC;AAE5B,QAAA,UAAU,GAAS;IAC9B,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE;QACJ,MAAM,EAAE,IAAI;KACb;IACD,SAAS,EAAE,cAAM,OAAA,CACf,8BAAC,aAAQ;QACP,8BAAC,SAAI,IACH,IAAI,EAAC,SAAS,EACd,YAAY,EAAE,cAAM,OAAA,IAAI,YAAY,EAAE,EAAlB,CAAkB,EACtC,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,CAAC,EAC7D,OAAO,EAAE,OAAO,GAChB,CACO,CACZ,EATgB,CAShB;CACF,CAAC;AAEF;IAA2B,gCAAM;IAAjC;QAAA,qEAsBC;QAjBC,UAAI,GAAG,IAAA,cAAS,EAAe;YAC7B,IAAI,EAAE,MAAM;SACb,CAAC,CAAC;QAEH,WAAK,GAAG,IAAA,cAAS,EAAe;YAC9B,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;QAEH,cAAQ,GAAG,IAAA,cAAS,EAAe;YACjC,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,qBAAe,GAAG,IAAA,cAAS,EAAe;YACxC,IAAI,EAAE,iBAAiB;YACvB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;;IACL,CAAC;IArBQ,mBAAM,GAAb;QACE,OAAO,IAAI,YAAY,EAAE,CAAC;IAC5B,CAAC;IAmBH,mBAAC;AAAD,CAAC,AAtBD,CAA2B,WAAM,GAsBhC;AAED,IAAM,OAAO,GAA8B;IACzC,KAAK,EAAE,gBAAW;IAClB,MAAM,EAAE;QACN,IAAI,EAAE,SAAS;QACf,KAAK,EAAE;YACL,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,WAAW;SACrB;QACD,OAAO,EAAE,UAAO,MAAoB,EAAE,OAAkC;;;;4BACrD,qBAAM,KAAK,CAAC,aAAM,CAAC,UAAU,CAAC,IAAI,EAAE;4BACnD,MAAM,EAAE,aAAM,CAAC,UAAU,CAAC,MAAM;4BAChC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gCACnB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;gCAC7B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK;gCAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK;6BACtC,CAAC;4BACF,QAAQ,EAAE,QAAQ;4BAClB,WAAW,EAAE,aAAa;4BAC1B,OAAO,EAAE;gCACP,cAAc,EAAE,kBAAkB;6BACnC;yBACF,CAAC,EAAA;;wBAZI,QAAQ,GAAG,SAYf;wBACF,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE;4BAC1B,MAAM,IAAI,KAAK,CAAC,mCAA4B,QAAQ,CAAC,UAAU,CAAE,CAAC,CAAC;yBACpE;wBAEY,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA5B,IAAI,GAAG,SAAqB;wBAClC,IAAI,IAAI,CAAC,KAAK,EAAE;4BACd,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;yBAC7B;wBAED,sBAAO,uFAAuF,EAAC;;;aAChG;KACF;CACF,CAAC"}
|
package/generated/index.ts
CHANGED
|
@@ -8,11 +8,10 @@ import 'moment';
|
|
|
8
8
|
import 'react';
|
|
9
9
|
import 'react-dom';
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
/** Generate Source Graph */
|
|
13
12
|
|
|
14
|
-
const sourceGraph =
|
|
15
|
-
|
|
13
|
+
const sourceGraph =
|
|
14
|
+
'{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"/Omit"},{"v":"@proteinjs/user-ui/loginPage","value":{"packageName":"@proteinjs/user-ui","name":"loginPage","filePath":"/home/runner/work/user/user/packages/ui/src/pages/Login.tsx","qualifiedName":"@proteinjs/user-ui/loginPage","type":{"packageName":"@proteinjs/ui","name":"Page","filePath":null,"qualifiedName":"@proteinjs/ui/Page","typeParameters":[],"directParents":[{"packageName":"@proteinjs/ui","name":"Page","filePath":null,"qualifiedName":"@proteinjs/ui/Page","typeParameters":[],"directParents":null}]},"isExported":true,"isConst":true,"sourceType":0}},{"v":"@proteinjs/ui/Page"},{"v":"@proteinjs/user-ui/signupPage","value":{"packageName":"@proteinjs/user-ui","name":"signupPage","filePath":"/home/runner/work/user/user/packages/ui/src/pages/Signup.tsx","qualifiedName":"@proteinjs/user-ui/signupPage","type":{"packageName":"@proteinjs/ui","name":"Page","filePath":null,"qualifiedName":"@proteinjs/ui/Page","typeParameters":[],"directParents":[{"packageName":"@proteinjs/ui","name":"Page","filePath":null,"qualifiedName":"@proteinjs/ui/Page","typeParameters":[],"directParents":null}]},"isExported":true,"isConst":true,"sourceType":0}}],"edges":[{"v":"@proteinjs/user-ui/loginPage","w":"@proteinjs/ui/Page","value":"has type"},{"v":"@proteinjs/user-ui/signupPage","w":"@proteinjs/ui/Page","value":"has type"}]}';
|
|
16
15
|
|
|
17
16
|
/** Generate Source Links */
|
|
18
17
|
|
|
@@ -20,15 +19,13 @@ import { loginPage } from '../src/pages/Login';
|
|
|
20
19
|
import { signupPage } from '../src/pages/Signup';
|
|
21
20
|
|
|
22
21
|
const sourceLinks = {
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
'@proteinjs/user-ui/loginPage': loginPage,
|
|
23
|
+
'@proteinjs/user-ui/signupPage': signupPage,
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
|
|
28
26
|
/** Load Source Graph and Links */
|
|
29
27
|
|
|
30
28
|
import { SourceRepository } from '@proteinjs/reflection';
|
|
31
29
|
SourceRepository.merge(sourceGraph, sourceLinks);
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
export * from '../index';
|
|
31
|
+
export * from '../index';
|
package/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src/AuthenticatedPageContainer';
|
|
1
|
+
export * from './src/AuthenticatedPageContainer';
|
package/jest.config.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"ts",
|
|
11
|
-
"tsx",
|
|
12
|
-
"js",
|
|
13
|
-
"jsx",
|
|
14
|
-
"json",
|
|
15
|
-
"node"
|
|
16
|
-
],
|
|
17
|
-
"testEnvironment": "node"
|
|
18
|
-
}
|
|
2
|
+
roots: ['<rootDir>/test'],
|
|
3
|
+
transform: {
|
|
4
|
+
'^.+\\.tsx?$': 'ts-jest',
|
|
5
|
+
},
|
|
6
|
+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
|
|
7
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
8
|
+
testEnvironment: 'node',
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/user-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "User ui components",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@proteinjs/reflection": "1.1.1",
|
|
25
25
|
"@proteinjs/server-api": "1.1.1",
|
|
26
26
|
"@proteinjs/ui": "2.0.2",
|
|
27
|
-
"@proteinjs/user": "^1.0.
|
|
27
|
+
"@proteinjs/user": "^1.0.14",
|
|
28
28
|
"moment": "2.29.4",
|
|
29
29
|
"react": "18.2.0",
|
|
30
30
|
"react-dom": "18.2.0"
|
|
@@ -34,8 +34,14 @@
|
|
|
34
34
|
"@types/node": "14.0.13",
|
|
35
35
|
"@types/react": "18.2.23",
|
|
36
36
|
"@types/react-dom": "18.2.8",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "7.8.0",
|
|
38
|
+
"@typescript-eslint/parser": "7.8.0",
|
|
39
|
+
"eslint": "8.57.0",
|
|
40
|
+
"eslint-config-prettier": "9.1.0",
|
|
41
|
+
"eslint-plugin-prettier": "5.1.3",
|
|
37
42
|
"typescript": "5.2.2"
|
|
38
43
|
},
|
|
39
44
|
"main": "./dist/generated/index.js",
|
|
40
|
-
"types": "./dist/generated/index.d.ts"
|
|
41
|
-
|
|
45
|
+
"types": "./dist/generated/index.d.ts",
|
|
46
|
+
"gitHead": "64f1b34c95269d295ba43797c42c43d1c44433ea"
|
|
47
|
+
}
|
|
@@ -6,44 +6,48 @@ import { loginPath } from './pages/Login';
|
|
|
6
6
|
export type AuthenticatedPageContainerProps = Omit<PageContainerProps, 'auth'>;
|
|
7
7
|
|
|
8
8
|
export function AuthenticatedPageContainer(props: AuthenticatedPageContainerProps) {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const { ...other } = props;
|
|
10
|
+
const [isLoggedIn, setIsLoggedIn] = React.useState(UserAuth.isLoggedIn());
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
return (
|
|
13
|
+
<PageContainer
|
|
14
|
+
auth={{
|
|
15
|
+
isLoggedIn,
|
|
16
|
+
canViewPage: (page: Page) => {
|
|
17
|
+
if (page.auth?.public) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (page.auth?.allUsers) {
|
|
22
|
+
return UserAuth.isLoggedIn();
|
|
23
|
+
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
if (!page.auth?.roles) {
|
|
26
|
+
return UserAuth.hasRole('admin');
|
|
27
|
+
}
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
return UserAuth.hasRoles(page.auth?.roles);
|
|
30
|
+
},
|
|
31
|
+
login: loginPath,
|
|
32
|
+
logout: async () => {
|
|
33
|
+
const response = await fetch(routes.logout.path, {
|
|
34
|
+
method: routes.logout.method,
|
|
35
|
+
redirect: 'follow',
|
|
36
|
+
credentials: 'same-origin',
|
|
37
|
+
headers: {
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
if (response.status != 200) {
|
|
42
|
+
throw new Error(`Failed to log out`);
|
|
43
|
+
}
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
45
|
+
new UserRepo().setUser(guestUser);
|
|
46
|
+
setIsLoggedIn(false);
|
|
47
|
+
return loginPath;
|
|
48
|
+
},
|
|
49
|
+
}}
|
|
50
|
+
{...other}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
package/src/pages/Login.tsx
CHANGED
|
@@ -1,70 +1,72 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Page, Form, Fields, textField, FormButtons, clearButton, FormPage } from '@proteinjs/ui';
|
|
3
|
-
import { routes } from '@proteinjs/user'
|
|
3
|
+
import { routes } from '@proteinjs/user';
|
|
4
4
|
|
|
5
5
|
export const loginPath = 'login';
|
|
6
6
|
export const loginPage: Page = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
7
|
+
name: 'Login',
|
|
8
|
+
path: loginPath,
|
|
9
|
+
auth: {
|
|
10
|
+
public: true,
|
|
11
|
+
},
|
|
12
|
+
component: () => (
|
|
13
|
+
<FormPage>
|
|
14
|
+
<Form<LoginFields, typeof buttons>
|
|
15
|
+
name='Login'
|
|
16
|
+
createFields={() => new LoginFields()}
|
|
17
|
+
fieldLayout={['email', 'password']}
|
|
18
|
+
buttons={buttons}
|
|
19
|
+
/>
|
|
20
|
+
</FormPage>
|
|
21
|
+
),
|
|
22
|
+
};
|
|
23
23
|
|
|
24
24
|
class LoginFields extends Fields {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
static create() {
|
|
26
|
+
return new LoginFields();
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
email = textField<LoginFields>({
|
|
30
|
+
name: 'email',
|
|
31
|
+
});
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
password = textField<LoginFields>({
|
|
34
|
+
name: 'password',
|
|
35
|
+
isPassword: true,
|
|
36
|
+
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const buttons: FormButtons<LoginFields> = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
clear: clearButton,
|
|
41
|
+
login: {
|
|
42
|
+
name: 'Login',
|
|
43
|
+
style: {
|
|
44
|
+
color: 'primary',
|
|
45
|
+
variant: 'contained',
|
|
46
|
+
},
|
|
47
|
+
onClick: async (fields: LoginFields, buttons: FormButtons<LoginFields>) => {
|
|
48
|
+
const response = await fetch(routes.login.path, {
|
|
49
|
+
method: routes.login.method,
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
email: fields.email.field.value,
|
|
52
|
+
password: fields.password.field.value,
|
|
53
|
+
}),
|
|
54
|
+
redirect: 'follow',
|
|
55
|
+
credentials: 'same-origin',
|
|
56
|
+
headers: {
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
if (response.status != 200) {
|
|
61
|
+
throw new Error(`Failed to login, error: ${response.statusText}`);
|
|
62
|
+
}
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const body = await response.json();
|
|
65
|
+
if (body.error) {
|
|
66
|
+
throw new Error(body.error);
|
|
67
|
+
}
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
69
|
+
window.location.href = '/';
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
package/src/pages/Signup.tsx
CHANGED
|
@@ -1,79 +1,81 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Page, Form, Fields, textField, FormButtons, clearButton, FormPage } from '@proteinjs/ui';
|
|
3
|
-
import { routes } from '@proteinjs/user'
|
|
3
|
+
import { routes } from '@proteinjs/user';
|
|
4
4
|
|
|
5
5
|
export const signupPage: Page = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
6
|
+
name: 'Sign Up',
|
|
7
|
+
path: 'signup',
|
|
8
|
+
auth: {
|
|
9
|
+
public: true,
|
|
10
|
+
},
|
|
11
|
+
component: () => (
|
|
12
|
+
<FormPage>
|
|
13
|
+
<Form<SignupFields, typeof buttons>
|
|
14
|
+
name='Sign Up'
|
|
15
|
+
createFields={() => new SignupFields()}
|
|
16
|
+
fieldLayout={['name', 'email', 'password', 'confirmPassword']}
|
|
17
|
+
buttons={buttons}
|
|
18
|
+
/>
|
|
19
|
+
</FormPage>
|
|
20
|
+
),
|
|
21
|
+
};
|
|
22
22
|
|
|
23
23
|
class SignupFields extends Fields {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
static create() {
|
|
25
|
+
return new SignupFields();
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
name = textField<SignupFields>({
|
|
29
|
+
name: 'name',
|
|
30
|
+
});
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
email = textField<SignupFields>({
|
|
33
|
+
name: 'email',
|
|
34
|
+
});
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
password = textField<SignupFields>({
|
|
37
|
+
name: 'password',
|
|
38
|
+
isPassword: true,
|
|
39
|
+
});
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
confirmPassword = textField<SignupFields>({
|
|
42
|
+
name: 'confirmPassword',
|
|
43
|
+
isPassword: true,
|
|
44
|
+
});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const buttons: FormButtons<SignupFields> = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
48
|
+
clear: clearButton,
|
|
49
|
+
signup: {
|
|
50
|
+
name: 'Sign up',
|
|
51
|
+
style: {
|
|
52
|
+
color: 'primary',
|
|
53
|
+
variant: 'contained',
|
|
54
|
+
},
|
|
55
|
+
onClick: async (fields: SignupFields, buttons: FormButtons<SignupFields>) => {
|
|
56
|
+
const response = await fetch(routes.createUser.path, {
|
|
57
|
+
method: routes.createUser.method,
|
|
58
|
+
body: JSON.stringify({
|
|
59
|
+
name: fields.name.field.value,
|
|
60
|
+
email: fields.email.field.value,
|
|
61
|
+
password: fields.password.field.value,
|
|
62
|
+
}),
|
|
63
|
+
redirect: 'follow',
|
|
64
|
+
credentials: 'same-origin',
|
|
65
|
+
headers: {
|
|
66
|
+
'Content-Type': 'application/json',
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
if (response.status != 200) {
|
|
70
|
+
throw new Error(`Failed to signup, error: ${response.statusText}`);
|
|
71
|
+
}
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
const body = await response.json();
|
|
74
|
+
if (body.error) {
|
|
75
|
+
throw new Error(body.error);
|
|
76
|
+
}
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
78
|
+
return `Successfully created your account! Please check your email for an email confirmation.`;
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "./",
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"outDir": "./dist/",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"noImplicitAny": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"jsx": "react"
|
|
17
|
+
}
|
|
18
|
+
}
|