xonecas.io
4515
Nr

node-react-typescript-boilerplate / commit 0e668c8

Adds login form

Sean2023-01-10 0e668c84581a79d78b559394e60223737cc9d799 parent 2096e4a

21 files changed

client/build/asset-manifest.json+6−7
@@ -1,16 +1,15 @@
11 {
22 "files": {
3- "main.css": "/static/css/main.073c9b0a.css",
4- "main.js": "/static/js/main.df1af5b2.js",
3+ "main.css": "/static/css/main.e6c13ad2.css",
4+ "main.js": "/static/js/main.f9e77444.js",
55 "static/js/787.c4e7f8f9.chunk.js": "/static/js/787.c4e7f8f9.chunk.js",
6- "static/media/logo.svg": "/static/media/logo.6ce24c58023cc2f8fd88fe9d219db6c6.svg",
76 "index.html": "/index.html",
8- "main.073c9b0a.css.map": "/static/css/main.073c9b0a.css.map",
9- "main.df1af5b2.js.map": "/static/js/main.df1af5b2.js.map",
7+ "main.e6c13ad2.css.map": "/static/css/main.e6c13ad2.css.map",
8+ "main.f9e77444.js.map": "/static/js/main.f9e77444.js.map",
109 "787.c4e7f8f9.chunk.js.map": "/static/js/787.c4e7f8f9.chunk.js.map"
1110 },
1211 "entrypoints": [
13- "static/css/main.073c9b0a.css",
14- "static/js/main.df1af5b2.js"
12+ "static/css/main.e6c13ad2.css",
13+ "static/js/main.f9e77444.js"
1514 ]
1615 }
client/build/index.html+1−1
@@ -1 +1 @@
1-<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.df1af5b2.js"></script><link href="/static/css/main.07 …
1+<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.f9e77444.js"></script><link href="/static/css/main.e6 …
client/build/static/css/main.073c9b0a.css+0−2
@@ -1,2 +0,0 @@
1-body{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;margin:0}code{font-family:source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace}.App{text-align:center}.App-logo{height:40vmin;pointer-events:none}@media (prefers-reduced-motion:no-preference){.App-logo{-webkit-animation:App-logo-spin 20s linear infinite;animation:App-logo-spin 20s linea …
2-/*# sourceMappingURL=main.073c9b0a.css.map*/
client/build/static/css/main.073c9b0a.css.map+0−1
@@ -1 +0,0 @@
1-{"version":3,"file":"static/css/main.073c9b0a.css","mappings":"AAAA,KAKE,kCAAmC,CACnC,iCAAkC,CAJlC,mIAEY,CAHZ,QAMF,CAEA,KACE,uEAEF,CCZA,KACE,iBACF,CAEA,UACE,aAAc,CACd,mBACF,CAEA,8CACE,UACE,mDAA4C,CAA5C,2CACF,CACF,CAEA,YAKE,kBAAmB,CAJnB,wBAAyB,CAOzB,UAAY,CALZ,YAAa,CACb,qBAAsB,CAGtB,4BAA6B,CAD7B,sBAAuB,CAJvB,gBAOF,CAEA,UACE,aACF,CAEA,iCACE,GACE,8BAAuB,CAAvB,sBACF,CACA,GACE,+BAAyB,CAAzB,uBACF,CACF,CAPA,yBACE,GACE,8BAAuB,CAAvB,sBACF,CACA,GACE,+BAAyB,CAAzB,uBACF,CACF","sources":["index.css","App.css" …
client/build/static/css/main.e6c13ad2.css+2−0
@@ -0,0 +1,2 @@
1+body{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;margin:0}code{font-family:source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace}
2+/*# sourceMappingURL=main.e6c13ad2.css.map*/
client/build/static/css/main.e6c13ad2.css.map+1−0
@@ -0,0 +1 @@
1+{"version":3,"file":"static/css/main.e6c13ad2.css","mappings":"AAAA,KAKE,kCAAmC,CACnC,iCAAkC,CAJlC,mIAEY,CAHZ,QAMF,CAEA,KACE,uEAEF","sources":["index.css"],"sourcesContent":["body {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, …
client/build/static/js/main.df1af5b2.js+0−3
@@ -1,3 +0,0 @@
1-/*! For license information please see main.df1af5b2.js.LICENSE.txt */
2-!function(){"use strict";var e={463:function(e,n,t){var r=t(791),l=t(296);function a(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,t=1;t<arguments.length;t++)n+="&args[]="+encodeURIComponent(arguments[t]);return"Minified React error #"+e+"; visit "+n+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var o=new Set,u={};function i(e,n){s(e,n),s(e+"Capture",n)}function s(e,n){for(u[e]=n,e=0;e<n.length;e++)o.add …
3-//# sourceMappingURL=main.df1af5b2.js.map
client/build/static/js/main.df1af5b2.js.map+0−1
@@ -1 +0,0 @@
1-{"version":3,"file":"static/js/main.df1af5b2.js","mappings":";oDAYa,IAAIA,EAAGC,EAAQ,KAASC,EAAGD,EAAQ,KAAa,SAASE,EAAEC,GAAG,IAAI,IAAIC,EAAE,yDAAyDD,EAAEE,EAAE,EAAEA,EAAEC,UAAUC,OAAOF,IAAID,GAAG,WAAWI,mBAAmBF,UAAUD,IAAI,MAAM,yBAAyBF,EAAE,WAAWC,EAAE,gHAAgH,CAAC,IAAIK,EAAG,IAAIC,IAAIC,EAAG,CAAC,EAAE,SAASC,EAAGT,EAAEC,GAAGS,EAAGV,EAAEC,GAAGS,EAAGV,EAAE,UAAUC,EAAE,CACxb,SAASS,EAAGV,EAAEC,GAAW,IAARO,EAAGR,GAAGC,EAAMD,EAAE,EAAEA,EAAEC,EAAEG,OAAOJ,IAAIM,EAAGK,IAAIV,EAAED,GAAG,CAC5D,IAAIY,IAAK,qBAAqBC,QA …
client/build/static/js/main.f9e77444.js+3−0
@@ -0,0 +1,3 @@
1+/*! For license information please see main.f9e77444.js.LICENSE.txt */
2+!function(){var e={472:function(e){e.exports="object"==typeof self?self.FormData:window.FormData},463:function(e,n,t){"use strict";var r=t(791),a=t(296);function l(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,t=1;t<arguments.length;t++)n+="&args[]="+encodeURIComponent(arguments[t]);return"Minified React error #"+e+"; visit "+n+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var o=new Set,i={};function u(e …
3+//# sourceMappingURL=main.f9e77444.js.map
client/build/static/js/main.f9e77444.js.LICENSE.txt+0−0
client/build/static/js/main.f9e77444.js.map+1−0
@@ -0,0 +1 @@
1+{"version":3,"file":"static/js/main.f9e77444.js","mappings":";mCACAA,EAAOC,QAAyB,iBAARC,KAAmBA,KAAKC,SAAWC,OAAOD,2CCWrD,IAAIE,EAAGC,EAAQ,KAASC,EAAGD,EAAQ,KAAa,SAASE,EAAEC,GAAG,IAAI,IAAIC,EAAE,yDAAyDD,EAAEE,EAAE,EAAEA,EAAEC,UAAUC,OAAOF,IAAID,GAAG,WAAWI,mBAAmBF,UAAUD,IAAI,MAAM,yBAAyBF,EAAE,WAAWC,EAAE,gHAAgH,CAAC,IAAIK,EAAG,IAAIC,IAAIC,EAAG,CAAC,EAAE,SAASC,EAAGT,EAAEC,GAAGS,EAAGV,EAAEC,GAAGS,EAAGV,EAAE,UAAUC,EAAE,CACxb,SAASS,EAAGV,EAAEC,GAAW,IAARO,EAAGR,GAAGC,EAAMD,EAAE,EAAEA,EAAEC,EAAEG,OAAOJ,IAAI …
client/build/static/media/logo.6ce24c58023cc2f8fd88fe9d219db6c6.svg+0−1
@@ -1 +0,0 @@
1-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10- …
client/package-lock.json+39−0
@@ -11,10 +11,12 @@
1111 "@testing-library/jest-dom": "^5.16.5",
1212 "@testing-library/react": "^13.4.0",
1313 "@testing-library/user-event": "^13.5.0",
14+ "@types/axios": "^0.14.0",
1415 "@types/jest": "^27.5.2",
1516 "@types/node": "^16.18.11",
1617 "@types/react": "^18.0.26",
1718 "@types/react-dom": "^18.0.10",
19+ "axios": "^1.2.2",
1820 "react": "^18.2.0",
1921 "react-dom": "^18.2.0",
2022 "react-scripts": "5.0.1",
@@ -3626,6 +3628,15 @@
36263628 "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.1.tgz",
36273629 "integrity": "sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q=="
36283630 },
3631+ "node_modules/@types/axios": {
3632+ "version": "0.14.0",
3633+ "resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz",
3634+ "integrity": "sha512-KqQnQbdYE54D7oa/UmYVMZKq7CO4l8DEENzOKc4aBRwxCXSlJXGz83flFx5L7AWrOQnmuN3kVsRdt+GZPPjiVQ==",
3635+ "deprecated": "This is a stub types definition for axios (https://github.com/mzabriskie/axios). axios provides its own type definitions, so you don't need @types/axios installed!",
3636+ "dependencies": {
3637+ "axios": "*"
3638+ }
3639+ },
36293640 "node_modules/@types/babel__core": {
36303641 "version": "7.1.20",
36313642 "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.20.tgz",
@@ -4743,6 +4754,29 @@
47434754 "node": ">=4"
47444755 }
47454756 },
4757+ "node_modules/axios": {
4758+ "version": "1.2.2",
4759+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.2.2.tgz",
4760+ "integrity": "sha512-bz/J4gS2S3I7mpN/YZfGFTqhXTYzRho8Ay38w2otuuDR322KzFIWm/4W2K6gIwvWaws5n+mnb7D1lN9uD+QH6Q==",
4761+ "dependencies": {
4762+ "follow-redirects": "^1.15.0",
4763+ "form-data": "^4.0.0",
4764+ "proxy-from-env": "^1.1.0"
4765+ }
4766+ },
4767+ "node_modules/axios/node_modules/form-data": {
4768+ "version": "4.0.0",
4769+ "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
4770+ "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
4771+ "dependencies": {
4772+ "asynckit": "^0.4.0",
4773+ "combined-stream": "^1.0.8",
4774+ "mime-types": "^2.1.12"
4775+ },
4776+ "engines": {
4777+ "node": ">= 6"
4778+ }
4779+ },
47464780 "node_modules/axobject-query": {
47474781 "version": "2.2.0",
47484782 "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz",
@@ -13706,6 +13740,11 @@
1370613740 "node": ">= 0.10"
1370713741 }
1370813742 },
13743+ "node_modules/proxy-from-env": {
13744+ "version": "1.1.0",
13745+ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
13746+ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
13747+ },
1370913748 "node_modules/psl": {
1371013749 "version": "1.9.0",
1371113750 "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
client/package.json+1−0
@@ -11,6 +11,7 @@
1111 "@types/node": "^16.18.11",
1212 "@types/react": "^18.0.26",
1313 "@types/react-dom": "^18.0.10",
14+ "axios": "^1.2.2",
1415 "react": "^18.2.0",
1516 "react-dom": "^18.2.0",
1617 "react-scripts": "5.0.1",
client/src/App.css+0−37
@@ -1,38 +1 @@
1-.App {
2- text-align: center;
3-}
41
5-.App-logo {
6- height: 40vmin;
7- pointer-events: none;
8-}
9-
10-@media (prefers-reduced-motion: no-preference) {
11- .App-logo {
12- animation: App-logo-spin infinite 20s linear;
13- }
14-}
15-
16-.App-header {
17- background-color: #282c34;
18- min-height: 100vh;
19- display: flex;
20- flex-direction: column;
21- align-items: center;
22- justify-content: center;
23- font-size: calc(10px + 2vmin);
24- color: white;
25-}
26-
27-.App-link {
28- color: #61dafb;
29-}
30-
31-@keyframes App-logo-spin {
32- from {
33- transform: rotate(0deg);
34- }
35- to {
36- transform: rotate(360deg);
37- }
38-}
client/src/App.test.tsx+1−1
@@ -4,6 +4,6 @@ import App from './App';
44
55 test('renders learn react link', () => {
66 render(<App />);
7- const linkElement = screen.getByText(/learn react/i);
7+ const linkElement = screen.getByText(/Email/i);
88 expect(linkElement).toBeInTheDocument();
99 });
client/src/App.tsx+3−18
@@ -1,25 +1,10 @@
1-import React from 'react';
2-import logo from './logo.svg';
31 import './App.css';
2+import LoginForm from './components/login';
43
54 function App() {
5+ //@TODO: Check if user is logged in to skip login form
66 return (
7- <div className="App">
8- <header className="App-header">
9- <img src={logo} className="App-logo" alt="logo" />
10- <p>
11- Edit <code>src/App.tsx</code> and save to reload.
12- </p>
13- <a
14- className="App-link"
15- href="https://reactjs.org"
16- target="_blank"
17- rel="noopener noreferrer"
18- >
19- Learn React
20- </a>
21- </header>
22- </div>
7+ <LoginForm mode="register" />
238 );
249 }
2510
client/src/components/login/index.tsx+75−0
@@ -0,0 +1,75 @@
1+import React, { useState } from "react";
2+import axios from "axios";
3+
4+// @TODO: Add styled components
5+
6+export default function LoginForm({ mode }: { mode: "login" | "register" }) {
7+ const [email, setEmail] = useState("");
8+ const [name, setName] = useState("");
9+ const [password, setPassword] = useState("");
10+
11+ const handleSubmit = (e: React.MouseEvent | React.FormEvent) => {
12+ e.preventDefault();
13+
14+ axios
15+ .post(
16+ `/auth/${mode}`,
17+ {
18+ email,
19+ name,
20+ password,
21+ },
22+ {
23+ headers: {
24+ "Content-Type": "application/json",
25+ },
26+ }
27+ )
28+ .then((response) => {
29+ console.log(response);
30+ // Mark the user as logged in? if in the correct mode.
31+ })
32+ .catch((error) => {
33+ console.log(error);
34+ // Display error to the user:
35+ });
36+ };
37+
38+ return (
39+ <form onSubmit={(e) => handleSubmit(e)}>
40+ <p>
41+ <label>Email:</label>
42+ </p>
43+ <input
44+ type="text"
45+ onChange={(e) => setEmail(e.target.value)}
46+ value={email}
47+ />
48+
49+ {mode === "register" && (
50+ <>
51+ <p>
52+ <label>Name:</label>
53+ </p>
54+ <input
55+ type="text"
56+ onChange={(e) => setName(e.target.value)}
57+ value={name}
58+ />
59+ </>
60+ )}
61+
62+ <p>
63+ <label>Password:</label>
64+ </p>
65+ <input
66+ type="text"
67+ onChange={(e) => setPassword(e.target.value)}
68+ value={password}
69+ />
70+ <p>
71+ <button>Submit</button>
72+ </p>
73+ </form>
74+ );
75+}
dist/auth/index.js+8−9
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1010 };
1111 Object.defineProperty(exports, "__esModule", { value: true });
1212 exports.login = exports.register = void 0;
13+const index_1 = require("../index");
1314 // Make a test record:
1415 // const user = await prisma.user.create({
1516 // data: {
@@ -23,15 +24,13 @@ exports.login = exports.register = void 0;
2324 // console.log(users);
2425 function register(ctx, next) {
2526 return __awaiter(this, void 0, void 0, function* () {
26- const data = JSON.parse(ctx.request.body);
27- console.log(data);
28- // const user = await prisma.user.create({
29- // data: {
30- // name: "",
31- // email: "",
32- // password: "",
33- // },
34- // });
27+ const data = ctx.request.body;
28+ const user = yield index_1.prisma.user.create({
29+ data: data,
30+ });
31+ console.log(user);
32+ ctx.status = 201;
33+ ctx.response.body = user;
3534 next();
3635 });
3736 }
prisma/dev.db+0−0
Binary file, not shown.
src/auth/index.ts+12−16
@@ -15,26 +15,22 @@ import { prisma } from "../index";
1515 // console.log(users);
1616
1717 export async function register(ctx: Koa.ParameterizedContext, next: Koa.Next) {
18+ const data = ctx.request.body;
19+ const user = await prisma.user.create({
20+ data: data,
21+ });
1822
19- const data = JSON.parse(ctx.request.body)
20-
21- console.log(data)
22-
23- // const user = await prisma.user.create({
24- // data: {
25- // name: "",
26- // email: "",
27- // password: "",
28- // },
29- // });
23+ console.log(user)
3024
31- next()
25+ ctx.status = 201
26+ ctx.response.body = user
27+
28+ next();
3229 }
3330
3431 export async function login(ctx: Koa.ParameterizedContext, next: Koa.Next) {
35- const data = JSON.parse(ctx.request.body)
36- console.log(data)
37-
38- next()
32+ const data = JSON.parse(ctx.request.body);
33+ console.log(data);
3934
35+ next();
4036 }