@moudle/-user 0.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.
Files changed (41) hide show
  1. package/dist/module/api/login.d.ts +3 -0
  2. package/dist/module/api/login.d.ts.map +1 -0
  3. package/dist/module/api/login.js +40 -0
  4. package/dist/module/api/login.js.map +1 -0
  5. package/dist/module/api/register.d.ts +3 -0
  6. package/dist/module/api/register.d.ts.map +1 -0
  7. package/dist/module/api/register.js +41 -0
  8. package/dist/module/api/register.js.map +1 -0
  9. package/dist/module/api.d.ts +7 -0
  10. package/dist/module/api.d.ts.map +1 -0
  11. package/dist/module/api.js +10 -0
  12. package/dist/module/api.js.map +1 -0
  13. package/dist/module/config-api.d.ts +4 -0
  14. package/dist/module/config-api.d.ts.map +1 -0
  15. package/dist/module/config-api.js +7 -0
  16. package/dist/module/config-api.js.map +1 -0
  17. package/dist/module/config-ui.d.ts +5 -0
  18. package/dist/module/config-ui.d.ts.map +1 -0
  19. package/dist/module/config-ui.js +8 -0
  20. package/dist/module/config-ui.js.map +1 -0
  21. package/dist/module/db.d.ts +9 -0
  22. package/dist/module/db.d.ts.map +1 -0
  23. package/dist/module/db.js +45 -0
  24. package/dist/module/db.js.map +1 -0
  25. package/dist/module/jwt.d.ts +5 -0
  26. package/dist/module/jwt.d.ts.map +1 -0
  27. package/dist/module/jwt.js +44 -0
  28. package/dist/module/jwt.js.map +1 -0
  29. package/dist/module/page/LoginPage.d.ts +2 -0
  30. package/dist/module/page/LoginPage.d.ts.map +1 -0
  31. package/dist/module/page/LoginPage.js +31 -0
  32. package/dist/module/page/LoginPage.js.map +1 -0
  33. package/dist/module/page/RegisterPage.d.ts +2 -0
  34. package/dist/module/page/RegisterPage.d.ts.map +1 -0
  35. package/dist/module/page/RegisterPage.js +32 -0
  36. package/dist/module/page/RegisterPage.js.map +1 -0
  37. package/dist/module/ui.d.ts +5 -0
  38. package/dist/module/ui.d.ts.map +1 -0
  39. package/dist/module/ui.js +11 -0
  40. package/dist/module/ui.js.map +1 -0
  41. package/package.json +51 -0
@@ -0,0 +1,3 @@
1
+ import { Request, Response } from 'express';
2
+ export declare function login(request: Request, response: Response): Promise<void>;
3
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../module/api/login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK5C,wBAAsB,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,iBA2B/D"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.login = login;
7
+ const bcrypt_1 = __importDefault(require("bcrypt"));
8
+ const zod_1 = __importDefault(require("zod"));
9
+ const db_1 = require("../db");
10
+ const jwt_1 = require("../jwt");
11
+ async function login(request, response) {
12
+ const LoginRequest = zod_1.default.object({
13
+ email: zod_1.default.string(),
14
+ password: zod_1.default.string(),
15
+ });
16
+ let login_request;
17
+ try {
18
+ login_request = LoginRequest.parse(request.body);
19
+ }
20
+ catch (error) {
21
+ if (error instanceof zod_1.default.ZodError) {
22
+ response.status(400).send(error.message);
23
+ return;
24
+ }
25
+ }
26
+ const user = await db_1.User.findOneBy({ email: login_request.email });
27
+ if (!user) {
28
+ response.status(400).send('Email not found');
29
+ return;
30
+ }
31
+ if (!await bcrypt_1.default.compare(login_request.password, user.password)) {
32
+ response.status(400).send('Wrong Password!');
33
+ return;
34
+ }
35
+ response.send({
36
+ token: (0, jwt_1.signJWT)(user.id),
37
+ user
38
+ });
39
+ }
40
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../../module/api/login.ts"],"names":[],"mappings":";;;;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
1
+ import { Request, Response } from 'express';
2
+ export declare function register(request: Request, response: Response): Promise<void>;
3
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../module/api/register.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK5C,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,iBA4BlE"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.register = register;
7
+ const bcrypt_1 = __importDefault(require("bcrypt"));
8
+ const zod_1 = __importDefault(require("zod"));
9
+ const db_1 = require("../db");
10
+ const jwt_1 = require("../jwt");
11
+ async function register(request, response) {
12
+ const RegisterRequest = zod_1.default.object({
13
+ name: zod_1.default.string(),
14
+ email: zod_1.default.string(),
15
+ password: zod_1.default.string(),
16
+ });
17
+ let register_request;
18
+ try {
19
+ register_request = RegisterRequest.parse(request.body);
20
+ }
21
+ catch (error) {
22
+ if (error instanceof zod_1.default.ZodError) {
23
+ response.status(400).send(error.message);
24
+ return;
25
+ }
26
+ }
27
+ if (await db_1.User.existsBy({ email: register_request.email })) {
28
+ response.status(400).send('Email already used');
29
+ return;
30
+ }
31
+ const user = new db_1.User();
32
+ user.name = register_request.name;
33
+ user.email = register_request.email;
34
+ user.password = await bcrypt_1.default.hash(register_request.password, 10);
35
+ await user.save();
36
+ response.send({
37
+ token: (0, jwt_1.signJWT)(user.id),
38
+ user
39
+ });
40
+ }
41
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../../module/api/register.ts"],"names":[],"mappings":";;;;;AAMA,4BA4BC;AAlCD,oDAA4B;AAE5B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,CAAC;QACvB,IAAI;KACL,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { login } from "./api/login";
2
+ import { register } from "./api/register";
3
+ export declare const LIST_API_USER: {
4
+ 'POST /api/register': typeof register;
5
+ 'POST /api/login': typeof login;
6
+ };
7
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../module/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,eAAO,MAAM,aAAa;;;CAGzB,CAAA"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIST_API_USER = void 0;
4
+ const login_1 = require("./api/login");
5
+ const register_1 = require("./api/register");
6
+ exports.LIST_API_USER = {
7
+ 'POST /api/register': register_1.register,
8
+ 'POST /api/login': login_1.login
9
+ };
10
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../module/api.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,6CAA0C;AAE7B,QAAA,aAAa,GAAG;IAC3B,oBAAoB,EAAE,mBAAQ;IAC9B,iBAAiB,EAAE,aAAK;CACzB,CAAA"}
@@ -0,0 +1,4 @@
1
+ export declare let CONFIG_API_USER: {
2
+ jwt_secret_key: string;
3
+ };
4
+ //# sourceMappingURL=config-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-api.d.ts","sourceRoot":"","sources":["../../module/config-api.ts"],"names":[],"mappings":"AAAA,eAAO,IAAI,eAAe;;CAEzB,CAAA"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONFIG_API_USER = void 0;
4
+ exports.CONFIG_API_USER = {
5
+ jwt_secret_key: 'some-secret-key'
6
+ };
7
+ //# sourceMappingURL=config-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-api.js","sourceRoot":"","sources":["../../module/config-api.ts"],"names":[],"mappings":";;;AAAW,QAAA,eAAe,GAAG;IAC3B,cAAc,EAAE,iBAAiB;CAClC,CAAA"}
@@ -0,0 +1,5 @@
1
+ export declare let CONFIG_UI_USER: {
2
+ login_redirect_path: string;
3
+ register_redirect_path: string;
4
+ };
5
+ //# sourceMappingURL=config-ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-ui.d.ts","sourceRoot":"","sources":["../../module/config-ui.ts"],"names":[],"mappings":"AAAA,eAAO,IAAI,cAAc;;;CAGxB,CAAA"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONFIG_UI_USER = void 0;
4
+ exports.CONFIG_UI_USER = {
5
+ login_redirect_path: '/',
6
+ register_redirect_path: '/'
7
+ };
8
+ //# sourceMappingURL=config-ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-ui.js","sourceRoot":"","sources":["../../module/config-ui.ts"],"names":[],"mappings":";;;AAAW,QAAA,cAAc,GAAG;IAC1B,mBAAmB,EAAE,GAAG;IACxB,sBAAsB,EAAE,GAAG;CAC5B,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { BaseEntity } from "typeorm";
2
+ export declare class User extends BaseEntity {
3
+ id: number;
4
+ name: string;
5
+ email: string;
6
+ password: string;
7
+ created_at: Date;
8
+ }
9
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../module/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,UAAU,EAAoB,MAAM,SAAS,CAAA;AAE9F,qBACa,IAAK,SAAQ,UAAU;IAElC,EAAE,EAAG,MAAM,CAAC;IAGZ,IAAI,EAAG,MAAM,CAAC;IAGd,KAAK,EAAG,MAAM,CAAC;IAGf,QAAQ,EAAG,MAAM,CAAC;IAGlB,UAAU,EAAG,IAAI,CAAC;CACnB"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.User = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ let User = class User extends typeorm_1.BaseEntity {
15
+ id;
16
+ name;
17
+ email;
18
+ password;
19
+ created_at;
20
+ };
21
+ exports.User = User;
22
+ __decorate([
23
+ (0, typeorm_1.PrimaryGeneratedColumn)(),
24
+ __metadata("design:type", Number)
25
+ ], User.prototype, "id", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.Column)({ type: 'varchar', length: 500 }),
28
+ __metadata("design:type", String)
29
+ ], User.prototype, "name", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.Column)({ type: 'varchar', length: 500 }),
32
+ __metadata("design:type", String)
33
+ ], User.prototype, "email", void 0);
34
+ __decorate([
35
+ (0, typeorm_1.Column)({ type: 'varchar', length: 500 }),
36
+ __metadata("design:type", String)
37
+ ], User.prototype, "password", void 0);
38
+ __decorate([
39
+ (0, typeorm_1.CreateDateColumn)(),
40
+ __metadata("design:type", Date)
41
+ ], User.prototype, "created_at", void 0);
42
+ exports.User = User = __decorate([
43
+ (0, typeorm_1.Entity)()
44
+ ], User);
45
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../../module/db.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAA8F;AAGvF,IAAM,IAAI,GAAV,MAAM,IAAK,SAAQ,oBAAU;IAElC,EAAE,CAAU;IAGZ,IAAI,CAAU;IAGd,KAAK,CAAU;IAGf,QAAQ,CAAU;IAGlB,UAAU,CAAQ;CACnB,CAAA;AAfY,oBAAI;AAEf;IADC,IAAA,gCAAsB,GAAE;;gCACb;AAGZ;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;kCAC3B;AAGd;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;mCAC1B;AAGf;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;sCACvB;AAGlB;IADC,IAAA,0BAAgB,GAAE;8BACN,IAAI;wCAAC;eAdP,IAAI;IADhB,IAAA,gBAAM,GAAE;GACI,IAAI,CAehB"}
@@ -0,0 +1,5 @@
1
+ import { User } from "./db";
2
+ export declare function signJWT(data: any): string;
3
+ export declare function extractJWT<T = string>(token: string): Promise<T>;
4
+ export declare function getUserFromAuthHeader(authorization: string): Promise<User>;
5
+ //# sourceMappingURL=jwt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../module/jwt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,wBAAgB,OAAO,CAAC,IAAI,EAAE,GAAG,UAEhC;AAED,wBAAsB,UAAU,CAAC,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,cAazD;AAED,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoBhF"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.signJWT = signJWT;
7
+ exports.extractJWT = extractJWT;
8
+ exports.getUserFromAuthHeader = getUserFromAuthHeader;
9
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
10
+ const db_1 = require("./db");
11
+ const config_api_1 = require("./config-api");
12
+ function signJWT(data) {
13
+ return jsonwebtoken_1.default.sign(data, config_api_1.CONFIG_API_USER.jwt_secret_key);
14
+ }
15
+ async function extractJWT(token) {
16
+ return new Promise((resolve, reject) => {
17
+ jsonwebtoken_1.default.verify(token, config_api_1.CONFIG_API_USER.jwt_secret_key, async (err, data) => {
18
+ if (err) {
19
+ reject(err.toString());
20
+ }
21
+ resolve(data);
22
+ });
23
+ });
24
+ }
25
+ async function getUserFromAuthHeader(authorization) {
26
+ const [_, token] = authorization.split(" ");
27
+ if (!token) {
28
+ throw new Error(`Data tidak ditemukan`);
29
+ }
30
+ const id = await extractJWT(token);
31
+ if (!id && isNaN(parseInt(id))) {
32
+ throw new Error(`jwt tidak valid: ${token}`);
33
+ }
34
+ const user = await db_1.User.findOne({
35
+ where: {
36
+ id: parseInt(id),
37
+ }
38
+ });
39
+ if (!user) {
40
+ throw new Error(`data user id = ${id} tidak ditemukan.`);
41
+ }
42
+ return user;
43
+ }
44
+ //# sourceMappingURL=jwt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../module/jwt.ts"],"names":[],"mappings":";;;;;AAIA,0BAEC;AAED,gCAaC;AAED,sDAoBC;AA3CD,gEAA+B;AAC/B,6BAA4B;AAC5B,6CAA+C;AAE/C,SAAgB,OAAO,CAAC,IAAS;IAC/B,OAAO,sBAAG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 @@
1
+ export declare function LoginPage(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=LoginPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoginPage.d.ts","sourceRoot":"","sources":["../../../module/page/LoginPage.tsx"],"names":[],"mappings":"AAIA,wBAAgB,SAAS,4CAyCxB"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LoginPage = LoginPage;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const react_1 = require("react");
10
+ const config_ui_1 = require("../config-ui");
11
+ function LoginPage() {
12
+ const [email, setEmail] = (0, react_1.useState)('');
13
+ const [password, setPassword] = (0, react_1.useState)('');
14
+ const [loading, setLoading] = (0, react_1.useState)(false);
15
+ async function login() {
16
+ try {
17
+ setLoading(true);
18
+ const res = await axios_1.default.post('/api/login', { email, password });
19
+ localStorage.setItem('token', res.data.token);
20
+ window.location.href = config_ui_1.CONFIG_UI_USER.login_redirect_path;
21
+ }
22
+ catch (err) {
23
+ alert(err?.response.data.toString());
24
+ }
25
+ finally {
26
+ setLoading(false);
27
+ }
28
+ }
29
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("input", { type: "email", value: email, onChange: e => setEmail(e.target.value), placeholder: "Email" }) }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("input", { type: "password", value: password, onChange: e => setPassword(e.target.value), placeholder: "Password" }) }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("button", { onClick: login, children: loading ? 'Loading' : 'Login' }) })] }));
30
+ }
31
+ //# sourceMappingURL=LoginPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Lo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Q,EAAE,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC1C,WAAW,EAAC,UAAU,GAAG,GACvB,EACN,0CACE,mCAAQ,OAAO,EAAE,KAAK,YACnB,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,GACvB,GACL,IACF,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function RegisterPage(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=RegisterPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegisterPage.d.ts","sourceRoot":"","sources":["../../../module/page/RegisterPage.tsx"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,4CAgD3B"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RegisterPage = RegisterPage;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const axios_1 = __importDefault(require("axios"));
9
+ const react_1 = require("react");
10
+ const config_ui_1 = require("../config-ui");
11
+ function RegisterPage() {
12
+ const [name, setName] = (0, react_1.useState)('');
13
+ const [email, setEmail] = (0, react_1.useState)('');
14
+ const [password, setPassword] = (0, react_1.useState)('');
15
+ const [loading, setLoading] = (0, react_1.useState)(false);
16
+ async function register() {
17
+ try {
18
+ setLoading(true);
19
+ const res = await axios_1.default.post('/api/register', { email, password, name });
20
+ localStorage.setItem('token', res.data.token);
21
+ window.location.href = config_ui_1.CONFIG_UI_USER.register_redirect_path;
22
+ }
23
+ catch (err) {
24
+ alert(err?.response.data.toString());
25
+ }
26
+ finally {
27
+ setLoading(false);
28
+ }
29
+ }
30
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("input", { value: name, onChange: e => setName(e.target.value), placeholder: "Name" }) }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("input", { type: "email", value: email, onChange: e => setEmail(e.target.value), placeholder: "Email" }) }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("input", { type: "password", value: password, onChange: e => setPassword(e.target.value), placeholder: "Password" }) }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("button", { onClick: register, children: loading ? 'Loading' : 'Register' }) })] }));
31
+ }
32
+ //# sourceMappingURL=RegisterPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegisterPage.js","sourceRoot":"","sources":["../../../module/page/RegisterPage.tsx"],"names":[],"mappings":";;;;;AAIA,oCAgDC;;AApDD,kDAA0B;AAC1B,iCAAiC;AACjC,4CAA8C;AAE9C,SAAgB,YAAY;IAC1B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAS,EAAE,CAAC,CAAC;IAC7C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAS,EAAE,CAAC,CAAC;IAC/C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAS,EAAE,CAAC,CAAC;IACrD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAU,KAAK,CAAC,CAAC;IAEvD,KAAK,UAAU,QAAQ;QACrB,IAAI,CAAC;YACH,UAAU,CAAC,IAAI,CAAC,CAAC;YACjB,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YACzE,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC9C,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,0BAAc,CAAC,sBAAsB,CAAC;QAC/D,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,KAAK,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvC,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,CACL,4CACE,0CACE,kCACE,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACtC,WAAW,EAAC,MAAM,GAAG,GACnB,EACN,0CACE,kCACE,IAAI,EAAC,OAAO,EACZ,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACvC,WAAW,EAAC,OAAO,GAAG,GACpB,EACN,0CACE,kCACE,IAAI,EAAC,UAAU,EACf,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC1C,WAAW,EAAC,UAAU,GAAG,GACvB,EACN,0CACE,mCAAQ,OAAO,EAAE,QAAQ,YACtB,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,GAC1B,GACL,IACF,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const LIST_PAGE_USER: {
2
+ '/login': import("react/jsx-runtime").JSX.Element;
3
+ '/register': import("react/jsx-runtime").JSX.Element;
4
+ };
5
+ //# sourceMappingURL=ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../module/ui.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc;;;CAG1B,CAAA"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIST_PAGE_USER = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const LoginPage_1 = require("./page/LoginPage");
6
+ const RegisterPage_1 = require("./page/RegisterPage");
7
+ exports.LIST_PAGE_USER = {
8
+ '/login': (0, jsx_runtime_1.jsx)(LoginPage_1.LoginPage, {}),
9
+ '/register': (0, jsx_runtime_1.jsx)(RegisterPage_1.RegisterPage, {})
10
+ };
11
+ //# sourceMappingURL=ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.js","sourceRoot":"","sources":["../../module/ui.tsx"],"names":[],"mappings":";;;;AAAA,gDAA6C;AAC7C,sDAAmD;AAEtC,QAAA,cAAc,GAAG;IAC5B,QAAQ,EAAE,uBAAC,qBAAS,KAAG;IACvB,WAAW,EAAE,uBAAC,2BAAY,KAAG;CAC9B,CAAA"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@moudle/-user",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "dist/lib.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "scripts": {
10
+ "start": "npm run build && node dist",
11
+ "build": "rm -rf dist && tsc",
12
+ "typeorm": "typeorm-ts-node-commonjs",
13
+ "generate-migration": "npm run typeorm migration:generate -- $1 -d ./data-source.ts",
14
+ "migrate": "npm run typeorm migration:run -- -d ./data-source.ts"
15
+ },
16
+ "files": [
17
+ "dist/module",
18
+ "package.json"
19
+ ],
20
+ "keywords": [],
21
+ "author": "",
22
+ "license": "ISC",
23
+ "devDependencies": {
24
+ "@react-router/dev": "^7.15.1",
25
+ "@types/bcrypt": "^6.0.0",
26
+ "@types/cors": "^2.8.19",
27
+ "@types/express": "^5.0.6",
28
+ "@types/jsonwebtoken": "^9.0.10",
29
+ "@types/node": "^25.8.0",
30
+ "@types/react": "^19.2.14",
31
+ "@types/react-dom": "^19.2.3",
32
+ "@types/react-router-dom": "^5.3.3",
33
+ "ts-node": "^10.9.2",
34
+ "typescript": "^6.0.3"
35
+ },
36
+ "dependencies": {
37
+ "@moudle/start": "^0.0.3",
38
+ "@react-router/express": "^7.15.1",
39
+ "axios": "^1.16.1",
40
+ "bcrypt": "^6.0.0",
41
+ "cors": "^2.8.6",
42
+ "express": "^5.2.1",
43
+ "jsonwebtoken": "^9.0.3",
44
+ "mysql2": "^3.22.3",
45
+ "react-dom": "^19.2.6",
46
+ "react-router-dom": "^7.15.1",
47
+ "reflect-metadata": "^0.2.2",
48
+ "typeorm": "^0.3.29",
49
+ "zod": "^4.4.3"
50
+ }
51
+ }