diff --git a/api/.eslintrc.json b/api/.eslintrc.json index 46b980e..611096a 100644 --- a/api/.eslintrc.json +++ b/api/.eslintrc.json @@ -3,7 +3,8 @@ "env": { "node": true, "browser": false, - "es6": true + "es6": true, + "mocha": true }, "parserOptions": { "ecmaVersion": 2018 diff --git a/api/controllers/users.js b/api/controllers/users.js index 636e368..8a71b98 100644 --- a/api/controllers/users.js +++ b/api/controllers/users.js @@ -52,7 +52,6 @@ const login = async (req, res, next) => { try { user = await users.getByEmail(req.body.email); } catch (error) { - console.log(error); return next(error, null); } diff --git a/api/package.json b/api/package.json index 8acafc4..667ba4c 100644 --- a/api/package.json +++ b/api/package.json @@ -4,6 +4,7 @@ "description": "", "main": "app.js", "dependencies": { + "aws-sdk": "^2.792.0", "bcryptjs": "^2.4.3", "express": "^4.17.1", "jsonwebtoken": "^8.5.1", @@ -12,13 +13,17 @@ "shortid": "^2.2.15" }, "devDependencies": { + "chai": "^4.2.0", + "chai-http": "^4.3.0", "eslint": "^7.12.1", "eslint-config-prettier": "^6.15.0", + "faker": "^5.1.0", + "mocha": "^8.2.1", "prettier": "^2.1.2" }, "scripts": { "pretest": "eslint --ignore-path ../.gitignore .", - "test": "echo \"Error: no test specified\" && exit 1", + "test": "mocha", "format": "prettier --write \"**/*.{js,json,md,yml}\"" }, "author": "", diff --git a/site/package.json b/site/package.json index bbd7ef0..27371bc 100644 --- a/site/package.json +++ b/site/package.json @@ -15,11 +15,12 @@ }, "dependencies": { "gatsby": "^2.25.3", - "react": "^16.12.0", - "react-dom": "^16.12.0", - "react-router-dom": "^5.1.2", "js-cookie": "^2.2.1", - "moment": "^2.24.0" + "moment": "^2.24.0", + "react": "^16.12.0", + "react-bootstrap": "^1.4.0", + "react-dom": "^16.12.0", + "react-router-dom": "^5.1.2" }, "devDependencies": { "eslint": "^7.12.1", diff --git a/site/src/components/Auth/Auth.js b/site/src/components/Auth/Auth.js deleted file mode 100644 index 024f993..0000000 --- a/site/src/components/Auth/Auth.js +++ /dev/null @@ -1,284 +0,0 @@ -import React, { Component } from "react"; -import { Link } from "gatsby"; -import styles from "./Auth.module.css"; -import { userRegister, userLogin, userGet, saveSession } from "../../utils"; - -class Auth extends Component { - constructor(props) { - super(props); - - const pathName = window.location.pathname.replace("/", ""); - - this.state = {}; - this.state.state = pathName; - this.state.loading = true; - this.state.error = null; - this.state.formEmail = ""; - this.state.formPassword = ""; - - // Bindings - this.handleFormInput = this.handleFormInput.bind(this); - this.handleFormSubmit = this.handleFormSubmit.bind(this); - this.handleFormTypeChange = this.handleFormTypeChange.bind(this); - } - - /** - * Component did mount - */ - componentDidMount() { - this.setState({ - loading: false, - }); - - // Clear query params - const url = document.location.href; - window.history.pushState({}, "", url.split("?")[0]); - } - - /** - * Handles a form change - */ - handleFormTypeChange(type) { - this.setState({ state: type }, () => { - this.props.history.push(`/${type}`); - }); - } - - /** - * Handle text changes within form fields - */ - handleFormInput(field, value) { - value = value.trim(); - - const nextState = {}; - nextState[field] = value; - - this.setState(Object.assign(this.state, nextState)); - } - - /** - * Handles form submission - * @param {object} evt - */ - async handleFormSubmit(evt) { - evt.preventDefault(); - - this.setState({ loading: true }); - - // Validate email - if (!this.state.formEmail) { - return this.setState({ - loading: false, - formError: "email is required", - }); - } - - // Validate password - if (!this.state.formPassword) { - return this.setState({ - loading: false, - formError: "password is required", - }); - } - - let token; - try { - if (this.state.state === "register") { - token = await userRegister( - this.state.formEmail, - this.state.formPassword - ); - } else { - token = await userLogin( - this.state.formEmail, - this.state.formPassword - ); - } - } catch (error) { - console.log(error); - if (error.message) { - this.setState({ - formError: error.message, - loading: false, - }); - } else { - this.setState({ - formError: - "Sorry, something unknown went wrong. Please try again.", - loading: false, - }); - } - return; - } - - // Fetch user record and set session in cookie - let user = await userGet(token.token); - user = user.user; - saveSession(user.id, user.email, token.token); - - window.location.replace("/"); - } - - render() { - return ( -
-
- {/* Logo */} - - - serverless-fullstack-application - - - {/* Loading */} - - {this.state.loading &&
loading, man!
} - - {/* Registration Form */} - - {!this.state.loading && ( -
-
{ - this.handleFormTypeChange("register"); - }} - > - Register -
-
{ - this.handleFormTypeChange("login"); - }} - > - Sign-In -
-
- )} - - {this.state.state === "register" && !this.state.loading && ( -
-
-
- - { - this.handleFormInput( - "formEmail", - e.target.value - ); - }} - /> -
-
- - { - this.handleFormInput( - "formPassword", - e.target.value - ); - }} - /> -
- - {this.state.formError && ( -
- {this.state.formError} -
- )} - - -
-
- )} - - {this.state.state === "login" && !this.state.loading && ( -
-
-
- - { - this.handleFormInput( - "formEmail", - e.target.value - ); - }} - /> -
-
- - { - this.handleFormInput( - "formPassword", - e.target.value - ); - }} - /> -
- - {this.state.formError && ( -
- {this.state.formError} -
- )} - - -
-
- )} -
-
- ); - } -} - -export default Auth; diff --git a/site/src/components/Auth/Auth.module.css b/site/src/components/Auth/Auth.module.css deleted file mode 100644 index e69de29..0000000 diff --git a/site/src/components/Dashboard/Dashboard.js b/site/src/components/Dashboard/Dashboard.js deleted file mode 100644 index b27ac09..0000000 --- a/site/src/components/Dashboard/Dashboard.js +++ /dev/null @@ -1,69 +0,0 @@ -import React, { Component } from "react"; -import { withRouter } from "react-router-dom"; -import styles from "./Dashboard.module.css"; -import { getSession, deleteSession } from "../../utils"; - -class Dashboard extends Component { - constructor(props) { - super(props); - this.state = {}; - - // Bindings - this.logout = this.logout.bind(this); - } - - async componentDidMount() { - const userSession = getSession(); - - this.setState({ - session: userSession, - }); - } - - /** - * Log user out by clearing cookie and redirecting - */ - logout() { - deleteSession(); - this.props.history.push(`/`); - } - - render() { - return ( -
-
- {/* Navigation */} - -
-
- {this.state.session - ? this.state.session.userEmail - : ""} -
-
- logout -
-
- - {/* Content */} - -
-
- serverless-fullstack-application -
- -
- Welcome to your serverless fullstack dashboard... -
-
-
-
- ); - } -} - -export default withRouter(Dashboard); diff --git a/site/src/components/Dashboard/Dashboard.module.css b/site/src/components/Dashboard/Dashboard.module.css deleted file mode 100644 index e69de29..0000000 diff --git a/site/src/pages/index.js b/site/src/pages/index.js index 00217e2..23f2a29 100644 --- a/site/src/pages/index.js +++ b/site/src/pages/index.js @@ -1,11 +1,14 @@ import React from "react"; -import Auth from "../components/Auth/Auth"; +import { Container, Row, Col } from "react-bootstrap"; export default function Home() { return ( -
-

Hello world!

- -
+ + + +

Hello world!

+ +
+
); }