From fd83cd728a19bc5aa092294ff475026e3f6397f9 Mon Sep 17 00:00:00 2001 From: Asten Mies Date: Thu, 13 Jul 2017 01:35:30 +0200 Subject: [PATCH 01/10] SignUp SignIn SignOut --- .gitignore | 1 + actions/index.js | 13 +++ components/Header.js | 16 +++- components/LinkList.js | 28 ++++++- components/SignInForm.js | 113 +++++++++++++++++++++++++ components/SignUpForm.js | 134 ++++++++++++++++++++++++++++++ containers/Header.js | 16 ++++ containers/SignInFormContainer.js | 61 ++++++++++++++ containers/SignUpFormContainer.js | 80 ++++++++++++++++++ libraries/apolloClient.js | 3 +- libraries/redirect.js | 13 +++ libraries/reducer.js | 6 +- libraries/reducers/authReducer.js | 16 ++++ libraries/reduxStore.js | 10 +++ package.json | 1 + pages/create.js | 2 +- pages/details.js | 2 +- pages/index.js | 2 +- pages/signin.js | 15 ++++ pages/signup.js | 15 ++++ routes.js | 12 +++ yarn.lock | 36 +++++--- 22 files changed, 571 insertions(+), 24 deletions(-) create mode 100644 actions/index.js create mode 100644 components/SignInForm.js create mode 100644 components/SignUpForm.js create mode 100644 containers/Header.js create mode 100644 containers/SignInFormContainer.js create mode 100644 containers/SignUpFormContainer.js create mode 100644 libraries/redirect.js create mode 100644 libraries/reducers/authReducer.js create mode 100644 pages/signin.js create mode 100644 pages/signup.js diff --git a/.gitignore b/.gitignore index 2fe34731..b7487c39 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .next/ config.js .env +yarn.lock coverage/ # Created by https://www.gitignore.io/api/node,macos,linux,windows,webstorm,sublimetext,visualstudiocode diff --git a/actions/index.js b/actions/index.js new file mode 100644 index 00000000..ef1cc078 --- /dev/null +++ b/actions/index.js @@ -0,0 +1,13 @@ +export const AUTH_SIGNIN = 'AUTH_SIGNIN'; +export const AUTH_SIGNOUT = 'AUTH_SIGNOUT'; +const localForage = require('localforage'); + +export const signIn = token => { + localForage.setItem('accessToken', token); + return { type: AUTH_SIGNIN }; +}; + +export const signOut = () => { + localForage.removeItem('accessToken'); + return { type: AUTH_SIGNOUT }; +}; diff --git a/components/Header.js b/components/Header.js index 44ce447b..0519193d 100644 --- a/components/Header.js +++ b/components/Header.js @@ -2,14 +2,24 @@ import PropTypes from 'prop-types'; import styled from 'styled-components'; import LinkList from './LinkList'; -const Header = ({ className, pathname }) => +const Header = ({ className, pathname, authenticated, logout }) =>
- +
; +Header.defaultProps = { + authenticated: false +}; + Header.propTypes = { pathname: PropTypes.string.isRequired, - className: PropTypes.string.isRequired + className: PropTypes.string.isRequired, + authenticated: PropTypes.bool.isRequired, + logout: PropTypes.func.isRequired }; export default styled(Header)` diff --git a/components/LinkList.js b/components/LinkList.js index 1081fb1b..496f60a8 100644 --- a/components/LinkList.js +++ b/components/LinkList.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import styled from 'styled-components'; import { Router } from '../routes'; -const LinkList = ({ className, pathname }) => +const LinkList = ({ className, pathname, authenticated, logout }) =>