Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/daniel/user profile #18

Open
wants to merge 199 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
5d48ee1
integrated tailwind and antdesign
justiceotuya Apr 20, 2019
f4d5f33
removed taiwindcss and rewrote the readme
justiceotuya Apr 21, 2019
7884570
Merge pull request #2 from team-helpme/feature/justiceotuya/integrate…
uimarshall Apr 21, 2019
24daa0b
finished the Landing Page
justiceotuya Apr 24, 2019
e6f1ab5
added next.config.js to .eslintignore
justiceotuya Apr 24, 2019
a1abd99
fixed linting errors for the front page
justiceotuya Apr 24, 2019
d8e3395
deletes hound.yml and make changes to travis.yml
uimarshall Apr 24, 2019
3cf3911
Merge pull request #4 from team-helpme/feature/marshall/delete-hound
justiceotuya Apr 25, 2019
501acef
fixed Landing page Bug reported by travis ci
justiceotuya Apr 25, 2019
8235020
Merge pull request #3 from team-helpme/feature/justiceotuya/finished-…
uimarshall Apr 25, 2019
d375028
fixed Landing page linting
justiceotuya Apr 26, 2019
c3851a1
Merge pull request #5 from team-helpme/fix/justiceotuya/fixed-linting…
uimarshall Apr 26, 2019
976ce3c
add basic expess server set up and database set up in mlab
uimarshall Apr 27, 2019
08ade0b
remove Uche Nnadi as author in package.json file
uimarshall Apr 27, 2019
2cfa498
Merge pull request #6 from team-helpme/feature/marshall/basic-express…
uimarshall Apr 29, 2019
0995fc0
Merge branch 'master' of https://github.com/team-helpme/helpme
uimarshall May 2, 2019
ad478aa
creates the user model and tests for basic crud operation
uimarshall May 2, 2019
f521f69
deleted test/package.json
uimarshall May 2, 2019
a55ecf8
add jest-mongodb-config file for jest testing
uimarshall May 4, 2019
45222d2
created the profile model and routes for creating and updating profile
cimthog May 4, 2019
86c7285
creates the user api-routes
uimarshall May 4, 2019
cc6171c
make module.exports = User = mongoose.model('users', UserSchema); int…
uimarshall May 9, 2019
cf2e827
modified User.js to create a new PR
uimarshall May 9, 2019
78a5a1d
created user profile routes
cimthog May 11, 2019
8c6102b
added ds_store to gitignore
justiceotuya May 13, 2019
27e3f21
refactored the landing page
justiceotuya May 13, 2019
3c1c139
refactored landing page and layout
justiceotuya May 14, 2019
2ee7d8a
made changes to file
justiceotuya May 15, 2019
7649664
made changes to file
justiceotuya May 15, 2019
474bbe7
made changes to file
justiceotuya May 15, 2019
0f4a222
made changes to file
justiceotuya May 15, 2019
78a2893
made changes to file
justiceotuya May 15, 2019
7cd2e3e
Merge pull request #14 from team-helpme/feature/justiceotuya/refactor…
uimarshall May 15, 2019
ad9aa00
finished login page
justiceotuya May 15, 2019
972f579
finished login page
justiceotuya May 15, 2019
7bbd73c
finished login page
justiceotuya May 15, 2019
325d9f0
finished login
justiceotuya May 15, 2019
adc1db5
finised the signup page
justiceotuya May 15, 2019
191d425
changed constants to capital letters
justiceotuya May 15, 2019
59c1b65
finished CRUD operation for profile model
cimthog May 16, 2019
a546e93
made few changes
cimthog May 16, 2019
06e4274
removed unnecessary console.log
cimthog May 16, 2019
4a8b49c
Merge branch 'master' of https://github.com/team-helpme/helpme
uimarshall May 17, 2019
0eb9aab
Merge branch 'master' into feature/marshall/create-user-model
uimarshall May 17, 2019
25351ec
fixed errors in the login and signup pages"
justiceotuya May 17, 2019
1dfd1ea
resolved eslint confilicts
cimthog May 17, 2019
7f30d46
removed empty test file
cimthog May 17, 2019
247a07a
modified User model and remove test folder
uimarshall May 17, 2019
8c841d8
Merge pull request #9 from team-helpme/feature/marshall/create-user-m…
justiceotuya May 17, 2019
40e9c73
Merge branch 'master' of https://github.com/team-helpme/helpme into f…
justiceotuya May 17, 2019
b1770c4
changed booleans to question format, added propTypes checking to Logi…
justiceotuya May 17, 2019
e7b11db
fix doc indent
justiceotuya May 18, 2019
38f6aa6
created user registration route in the user-api-routes
uimarshall May 21, 2019
a7136f6
Merge branch 'feature/marshall/create-user-api-routes' of https://git…
uimarshall May 21, 2019
eb6e663
fixed linting errors
uimarshall May 21, 2019
c8a4a94
refactored the forms
justiceotuya May 21, 2019
11bc109
remove duplicate lines of code in server/index.js and destructure req…
uimarshall May 21, 2019
ed0535d
refactored the forms
justiceotuya May 21, 2019
f1129a6
fixed minor indentation and naming issue
justiceotuya May 22, 2019
61ef2d3
put destructuring on line 13 in routes/api/users.js and modified erro…
uimarshall May 22, 2019
2abd7fa
Merge pull request #19 from team-helpme/feature/marshall/create-user-…
justiceotuya May 22, 2019
f840f32
merged package.json
justiceotuya May 22, 2019
a822058
Merge pull request #17 from team-helpme/feature/justiceotuya/signup
uimarshall May 22, 2019
6483de4
fixed path
cimthog May 22, 2019
e64dbd3
merged files
cimthog May 22, 2019
ba40879
added forget password page
justiceotuya May 22, 2019
d6f70cd
removed conflicting file
cimthog May 22, 2019
a4a46eb
added forget password page
justiceotuya May 22, 2019
51192ad
added forget password page
justiceotuya May 22, 2019
a8ff5f4
resolve conflicts
cimthog May 22, 2019
301091d
resolved conflicts
cimthog May 22, 2019
81359aa
resolved conflicts
cimthog May 22, 2019
1bfba61
resolved conflicts
cimthog May 22, 2019
353f44b
fixed duplicate comment
justiceotuya May 22, 2019
eb327a3
moved strings to constatnt file
justiceotuya May 22, 2019
82865cc
moved strings to constatnt file
justiceotuya May 22, 2019
224bda6
made minor changes as regards to inline styles
justiceotuya May 22, 2019
7f29244
created a function for validation
cimthog May 22, 2019
2a0d89a
Merge pull request #20 from team-helpme/feature/justiceotuya/forgot_p…
uimarshall May 23, 2019
86016a8
check for empty entries in a better way
cimthog May 24, 2019
70a416b
implements auth0 and user login, logout route
uimarshall May 24, 2019
7c1ba03
implements auth0 and user login, logout route
uimarshall May 24, 2019
6b343d8
fixed some linting issues
uimarshall May 24, 2019
ad9d2cb
resolve linting issues
uimarshall May 25, 2019
f407936
modified the code to give space to if statement blocks
uimarshall May 25, 2019
96a213a
checked if user exists when creating profile
cimthog May 26, 2019
80433a0
Merge pull request #21 from team-helpme/feature/Daniel/user-profile
uimarshall May 27, 2019
a4f8f76
destructure process.env in config/passport.js and routes/api/users.js
uimarshall May 27, 2019
7aee434
adds user input validations
uimarshall May 28, 2019
9450e28
create Post model
uimarshall May 28, 2019
b0f7fd0
Merge pull request #23 from team-helpme/feature/marshall/login-with-p…
justiceotuya May 28, 2019
b2a22d0
clean up code, pads if statement and change variables naming to camel…
uimarshall May 28, 2019
e3a2962
fixed glithes in landing page
justiceotuya May 28, 2019
127e3ba
Created the TimeLine Page
justiceotuya May 28, 2019
94118a1
Merge pull request #25 from team-helpme/feature/marshall/create-Post-…
justiceotuya May 29, 2019
862d057
minor fix
justiceotuya May 29, 2019
8683b2c
fix indent
justiceotuya May 29, 2019
6bfc564
move all strings to constant file and seperated module imports from c…
justiceotuya May 29, 2019
e31541b
removed trailing spaces
justiceotuya May 29, 2019
e66940b
Merge pull request #26 from team-helpme/fix/justice/landing_page
uimarshall May 30, 2019
774fa8b
pads if statement and change variables naming to camel case in valida…
uimarshall May 30, 2019
9e9ce36
merged master
justiceotuya May 30, 2019
30e2646
removed trailing spaces
justiceotuya May 30, 2019
01abf18
removed bindings so as to implement es6 class structure
justiceotuya May 30, 2019
a8ab903
Merge pull request #27 from team-helpme/feature/justiceotuya/Timeline…
justiceotuya May 30, 2019
576f671
Merge pull request #24 from team-helpme/feature/marshall/user-input-v…
uimarshall May 30, 2019
f68ec7d
adds userInview to conditioner render user using auth0
uimarshall May 30, 2019
74fb73e
finished the ui of the timeline
justiceotuya May 30, 2019
4717f38
Merge pull request #29 from team-helpme/feature/marshall/make-users-a…
uimarshall May 30, 2019
79d9c30
finished the ui of the timeline
justiceotuya May 31, 2019
ad155db
finished the ui of the timeline
justiceotuya May 31, 2019
e7721b5
merged wint master
justiceotuya Jun 1, 2019
66d27d6
fixed comments of the createPostButton function
justiceotuya Jun 1, 2019
e208e70
adds Post routes
uimarshall Jun 1, 2019
0e4ecc3
created forum topic and routes
cimthog Jun 1, 2019
2019299
fixed merge conflict
cimthog Jun 1, 2019
c81b042
Merge pull request #30 from team-helpme/feature/justiceotuya/Timeline…
uimarshall Jun 3, 2019
00188cf
integrated redux
justiceotuya Jun 3, 2019
a9c6383
integrated redux, deleted authenication folder since Auth0 is providi…
justiceotuya Jun 3, 2019
c0e65f3
tried fixing travis lint error
justiceotuya Jun 3, 2019
bd56212
fixed renamed folders
justiceotuya Jun 3, 2019
2ad3c11
fixed static folder not tracked by git
justiceotuya Jun 3, 2019
72c3239
Merge branch 'feature/justiceotuya/Adding_Redux' of https://github.co…
justiceotuya Jun 3, 2019
76bc88d
adding actions and reducers
justiceotuya Jun 5, 2019
1cf25fd
adding actions and reducers
justiceotuya Jun 5, 2019
c9e6adf
connected like, comment and fav button to redux
justiceotuya Jun 5, 2019
b536565
refactorin ang fixing errors
justiceotuya Jun 5, 2019
6658eaf
refactorin and fixing errors
justiceotuya Jun 5, 2019
87947ef
refactorin and fixing errors
justiceotuya Jun 5, 2019
72f93c8
Merge pull request #32 from team-helpme/feature/justiceotuya/Adding_R…
uimarshall Jun 6, 2019
287d775
handled like, favourite, comment toggling and status posting with redux
justiceotuya Jun 6, 2019
d0865ff
implements http-status-codes and JSend
uimarshall Jun 6, 2019
9041877
fixed convention for error messages
uimarshall Jun 7, 2019
bd71038
Merge pull request #31 from team-helpme/feature/marshall/create-Post-…
justiceotuya Jun 7, 2019
e84a9bc
fixed conflict
cimthog Jun 9, 2019
3e6383a
fixed error
justiceotuya Jun 9, 2019
bc22b65
fixed error
justiceotuya Jun 9, 2019
99a61ce
Fixed direct state Mutation and formatting
justiceotuya Jun 10, 2019
26b070a
added timeline comment posts
justiceotuya Jun 10, 2019
a4bd42a
formatting lists on each line
justiceotuya Jun 10, 2019
f453a57
made minor format change on handleCreateStatus function
justiceotuya Jun 10, 2019
9083e14
grouped timeline actions in mapDispatchToProps
justiceotuya Jun 10, 2019
3a24942
finished the timeline comments
justiceotuya Jun 10, 2019
d5604eb
fixed minor pr errors and bugs
justiceotuya Jun 10, 2019
5bcb0f2
Merge branch 'master' of https://github.com/team-helpme/helpme into f…
justiceotuya Jun 10, 2019
3af30ef
Merge pull request #33 from team-helpme/feature/justiceotuya/connecti…
uimarshall Jun 10, 2019
6d050cc
Added update post component
justiceotuya Jun 10, 2019
76f53de
merged from master
justiceotuya Jun 10, 2019
6b7d1c5
made post routes secured
cimthog Jun 10, 2019
7012034
fixed comment
justiceotuya Jun 10, 2019
5a10c68
fixed comment
justiceotuya Jun 10, 2019
b5d3322
fixed comment
justiceotuya Jun 10, 2019
336bcf0
Merge pull request #34 from team-helpme/feature/justiceotuya/timeline…
justiceotuya Jun 10, 2019
3da7f4b
connected redux saga
justiceotuya Jun 11, 2019
4915b3d
connected redux saga
justiceotuya Jun 11, 2019
25d75b8
connected redux saga
justiceotuya Jun 11, 2019
3b522ef
connected redux saga
justiceotuya Jun 11, 2019
a5ebdc8
Moved controlled comment from redux to internal state and made pr cha…
justiceotuya Jun 12, 2019
c21e8ac
Finished timeline UI
justiceotuya Jun 12, 2019
e04ad89
Merge pull request #36 from team-helpme/feature/Daniel/user-profile
justiceotuya Jun 12, 2019
a5ea3be
Merge pull request #35 from team-helpme/feature/justiceotuya/Implemen…
justiceotuya Jun 12, 2019
108a0db
merged from masterMerge branch 'master' of https://github.com/team-he…
justiceotuya Jun 12, 2019
400af5d
Finished timeline UI
justiceotuya Jun 12, 2019
5a3f8b0
made some fixes from PR
justiceotuya Jun 13, 2019
98ddb9c
finished forum UI
justiceotuya Jun 13, 2019
77b4569
fixed saga and error handling
justiceotuya Jun 13, 2019
ff60ad6
error handling for sagas
justiceotuya Jun 13, 2019
03d59e9
removed unused code
justiceotuya Jun 13, 2019
ab4c488
fixed setOnlineFriendsError error
justiceotuya Jun 13, 2019
3490fcf
fixed data error
justiceotuya Jun 13, 2019
9df03bf
fixed forum pr review
justiceotuya Jun 13, 2019
21cb9d0
Merge pull request #37 from team-helpme/feature/justiceotuya/Finishin…
justiceotuya Jun 13, 2019
532b43f
merged with master
justiceotuya Jun 13, 2019
c9f88d2
Merge pull request #38 from team-helpme/feature/justiceotuya/Forum_Fe…
justiceotuya Jun 13, 2019
68b46f8
added redux to forum
justiceotuya Jun 13, 2019
22a21d6
fixed bug that made both comment and status input display same value …
justiceotuya Jun 13, 2019
1249c1d
Merge pull request #39 from team-helpme/feature/justiceotuya/Forum_Redux
justiceotuya Jun 14, 2019
e11fd5f
readded signup
justiceotuya Jun 14, 2019
4952f22
connected registration to backend
justiceotuya Jun 14, 2019
b7c1e4c
connected registration to backend
justiceotuya Jun 14, 2019
18c1058
made fixes
justiceotuya Jun 14, 2019
6389a8a
fixed saga
justiceotuya Jun 15, 2019
72d9a9d
fixed authentication
justiceotuya Jun 17, 2019
b3f0fc3
fixed authentication
justiceotuya Jun 17, 2019
9e60dce
fixed authentication
justiceotuya Jun 17, 2019
1b845f1
Merge pull request #40 from team-helpme/feature/justiceotuya/API_conn…
uimarshall Jun 17, 2019
321a6ee
merged with master Merge branch 'master' of https://github.com/team-h…
justiceotuya Jun 17, 2019
774f85c
fixed authentication test
justiceotuya Jun 17, 2019
c85237b
made fixes
justiceotuya Jun 17, 2019
75fcba8
made changes
justiceotuya Jun 17, 2019
77b4743
made fixes
justiceotuya Jun 17, 2019
5de865e
updates readme
uimarshall Jun 17, 2019
9903e54
made fixes from pr
justiceotuya Jun 17, 2019
8076458
change method of adding image
uimarshall Jun 17, 2019
3e6069b
made fixes from pr
justiceotuya Jun 17, 2019
4b61f40
Merge pull request #44 from team-helpme/feature/marshall/Update-ReadMe
justiceotuya Jun 17, 2019
0f0e76f
Merge pull request #43 from team-helpme/feature/justiceotuya/Authenti…
justiceotuya Jun 17, 2019
ca03102
connected Authentication and backend
justiceotuya Jun 17, 2019
227ed44
added profile to user schema
cimthog Jun 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"env": {
"development": {
"presets": [
"next/babel"
],
"plugins": [
"inline-react-svg"
]
},
"production": {
"presets": [
"next/babel"
],
"plugins": [
"inline-react-svg"
]
},
"test": {
"presets": [
[
"next/babel",
{
"preset-env": {
"modules": "commonjs"
}
}
]
],
"plugins": [
"inline-react-svg"
]
}
}
}
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
/tests/fixtures/**
/tests/performance/**
/tmp/**
next.config.js


# Add any other files or folders that you want eslint to ignore
8 changes: 6 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"browser": true,
"commonjs": true,
"es6": true,
"node": true
"node": true,
"jest": true
},
"parser": "babel-eslint",
"parserOptions":{
Expand Down Expand Up @@ -78,12 +79,15 @@
"react/no-danger": "error",
"react/jsx-pascal-case": "error",
"react/jsx-indent": ["error", 4],
"react/jsx-indent-props": ["error", 4],
"react/jsx-closing-bracket-location": "error",
"react/void-dom-elements-no-children": "error",
"react/jsx-tag-spacing": "error",
"react/jsx-no-literals": "error",
"react/jsx-wrap-multilines": "error",
"react/jsx-no-comment-textnodes": "error"
"react/jsx-no-comment-textnodes": "error",
"jsx-a11y/anchor-is-valid": 0,
"import/prefer-default-export": "off"
},
"settings": {
"react": {
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ build/Release
node_modules/
jspm_packages/
package-lock.json

.DS_Store
# TypeScript v1 declaration files
typings/

Expand Down Expand Up @@ -69,6 +69,7 @@ typings/

# next.js build output
.next
next.config.js

# nuxt.js build output
.nuxt
Expand Down
4 changes: 0 additions & 4 deletions .hound.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
language: node_js
node_js:
- "node"
script:
- npm run lint
- npm test
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# project-template
Document your applications API and general usage
# Project Help Me

Help Me is an app that connects Depressed people to each other, essentially, it is a social network for depressed people where affected individuals can connect to seek help and therapy.

![](static/helpme_landing.png)

## Development

- Clone this repo to your local machine using `git clone https://github.com/team-helpme/helpme`
- `cd helpme`
- `npm install`
- `npm run dev`

Antdesign is also used for the components, check <http://ant.design/docs/react/introduce>
7 changes: 7 additions & 0 deletions components/authentication/actionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const actionTypes = {
GET_USER_PROFILE: 'GET_USER_PROFILE',
LOGIN_FAILURE: 'LOGIN_FAILURE',
LOGIN_SUCCESS: 'LOGIN_SUCCESS',
};

export default actionTypes;
16 changes: 16 additions & 0 deletions components/authentication/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import actionTypes from './actionTypes';

const { LOGIN_FAILURE, LOGIN_SUCCESS, GET_USER_PROFILE } = actionTypes;

export const loginFailure = () => ({
type: LOGIN_FAILURE,
});

export const loginSuccess = () => ({
type: LOGIN_SUCCESS,
});

export const getUserProfile = payload => ({
payload,
type: GET_USER_PROFILE,
});
6 changes: 6 additions & 0 deletions components/authentication/components/Authentication.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.loading_Div {
height: 100vh;
width: 100vw;
display: grid;
place-content: center;
}
59 changes: 59 additions & 0 deletions components/authentication/components/Authentication.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-disable no-shadow */
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import Router from 'next/router';
import { Spin } from 'antd';

import { getUserProfile, loginFailure, loginSuccess } from '../actions';
import { getIsAuthenticated, getUsersProfile } from '../selectors';
import { handleAuthentication, isAuthenticated, login } from '../utils';
import { SIGNING_IN_TEXT } from '../constants';

class Authentication extends PureComponent {
componentDidMount() {
const { loginSuccess, loginFailure } = this.props;
try {
handleAuthentication().then(() => {
if (isAuthenticated()) {
loginSuccess();
Router.push('/timeline');
}
});
} catch (err) {
if (!isAuthenticated()) {
loginFailure();
login();
}
}
}

render() {
return (
<div className="loading_Div">
<Spin tip={SIGNING_IN_TEXT} size="large" />
</div>
);
}
}

const mapStateToProps = state => ({
isAuthenticated: getIsAuthenticated(state),
userProfile: getUsersProfile(state),
});

const authActions = {
getUserProfile,
loginFailure,
loginSuccess,
};

const mapDispatchToProps = dispatch => bindActionCreators(authActions, dispatch);

export default connect(mapStateToProps, mapDispatchToProps)(Authentication);

Authentication.propTypes = {
loginFailure: PropTypes.func.isRequired,
loginSuccess: PropTypes.func.isRequired,
};
6 changes: 6 additions & 0 deletions components/authentication/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'antd/dist/antd.css';

import './Authentication.css';
import Authentication from './Authentication';

export { Authentication };
2 changes: 2 additions & 0 deletions components/authentication/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const NAME = 'auth';
export const SIGNING_IN_TEXT = 'Signing you in ...';
9 changes: 9 additions & 0 deletions components/authentication/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as actions from './actions';
import * as components from './components';
import * as utils from './utils';
import authSagas from './sagas';
import reducers from './reducers';

export {
actions, components, authSagas, reducers, utils
};
23 changes: 23 additions & 0 deletions components/authentication/reducers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import actionTypes from './actionTypes';

const { GET_USER_PROFILE, LOGIN_FAILURE, LOGIN_SUCCESS } = actionTypes;

const initialState = {
isAuthenticated: false,
usersProfile: null,
};

export default (state = initialState, action) => {
const { payload, type } = action;

switch (type) {
case LOGIN_FAILURE:
return { ...state, isAuthenticated: false };
case LOGIN_SUCCESS:
return { ...state, isAuthenticated: true };
case GET_USER_PROFILE:
return { ...state, usersProfile: payload };
default:
return state;
}
};
14 changes: 14 additions & 0 deletions components/authentication/sagas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { takeEvery, put } from 'redux-saga/effects';

import actionTypes from './actionTypes';
import { getUserProfile } from './actions';

const { LOGIN_SUCCESS } = actionTypes;

function* handleGetUserProfile(payload) {
yield put(getUserProfile(payload));
}

export default function* watchProfileDataLoad() {
yield takeEvery(LOGIN_SUCCESS, handleGetUserProfile);
}
4 changes: 4 additions & 0 deletions components/authentication/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { NAME } from './constants';

export const getIsAuthenticated = state => state[NAME].isAuthenticated;
export const getUsersProfile = state => state[NAME].userProfile;
50 changes: 50 additions & 0 deletions components/authentication/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import auth0 from 'auth0-js';

export const authConfig = new auth0.WebAuth({
clientID: `${process.env.clientID}`,
domain: 'teamhelpme.auth0.com',
redirectUri: 'http://localhost:3000/auth/signed-in',
responseType: 'token id_token',
scope: 'openid profile email',
});

export const setSession = authResult => {
// Set the time that the access token will expire at
const expiresAt = JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime());
localStorage.setItem('access_token', authResult.accessToken);
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem('expires_at', expiresAt);
localStorage.setItem('profile', JSON.stringify(authResult.idTokenPayload));
};

export const login = () => {
authConfig.authorize();
};

export const logout = () => {
// Clear access token and ID token from local storage
localStorage.removeItem('access_token');
localStorage.removeItem('id_token');
localStorage.removeItem('expires_at');
localStorage.removeItem('profile');
};

export const handleAuthentication = () => new Promise((resolve, reject) => {
authConfig.parseHash((err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
setSession(authResult);
return resolve();
} if (err) {
login();
return reject();
}
return reject();
});
});

export const isAuthenticated = () => {
// Check whether the current time is past the
// access token's expiry time
const expiresAt = JSON.parse(localStorage.getItem('expires_at'));
return new Date().getTime() < expiresAt;
};
7 changes: 7 additions & 0 deletions components/forum/actionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const actionTypes = {
REQUEST_LOAD_FORUM_DATA: 'REQUEST_LOAD_FORUM_DATA',
REQUEST_SET_FORUM_DATA_ERROR: 'REQUEST_SET_FORUM_DATA_ERROR',
REQUEST_SET_FORUM_DATA_SUCCESS: 'REQUEST_SET_FORUM_DATA_SUCCESS',
};

export default actionTypes;
21 changes: 21 additions & 0 deletions components/forum/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import actionTypes from './actionTypes';

const {
REQUEST_LOAD_FORUM_DATA,
REQUEST_SET_FORUM_DATA_ERROR,
REQUEST_SET_FORUM_DATA_SUCCESS,
} = actionTypes;

export const loadForumData = () => ({
type: REQUEST_LOAD_FORUM_DATA,
});

export const setForumDataError = payload => ({
payload,
type: REQUEST_SET_FORUM_DATA_ERROR,
});

export const setForumDataSuccess = payload => ({
payload,
type: REQUEST_SET_FORUM_DATA_SUCCESS,
});
Loading