Skip to content

Commit 071238e

Browse files
committed
create auth module and fix broken paths
1 parent 83a224f commit 071238e

File tree

21 files changed

+70
-68
lines changed

21 files changed

+70
-68
lines changed

resources/assets/js/Main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
44
import { connect } from 'react-redux'
55

66
// import services actions
7-
import { fetchUser } from './store/services/auth'
7+
import { fetchUser } from './modules/auth/service'
88

99
// import components
1010
import Navigation from './common/navigation'

resources/assets/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Provider } from 'react-redux'
1919
import store from './store'
2020
import Routes from './routes'
2121

22-
import { authCheck } from './store/actions/auth'
22+
import { authCheck } from './modules/auth/store/actions'
2323

2424
store.dispatch(authCheck())
2525

resources/assets/js/common/navigation/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React, { Component } from 'react'
33
import PropTypes from 'prop-types'
44
import { connect } from 'react-redux'
5-
import { logout } from '../../store/services/auth'
5+
import { logout } from '../../modules/auth/service'
66

77
// import components
88
import { Link } from 'react-router-dom'

resources/assets/js/pages/login/Page.js renamed to resources/assets/js/modules/auth/pages/login/Page.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
44
import $ from 'jquery'
55
import _ from 'lodash'
66
import { Redirect } from 'react-router-dom'
7-
import { login } from '../../store/services/auth'
7+
import { login } from '../../service'
88
import { Validator } from 'ree-validate'
99

1010
// import components
@@ -14,21 +14,21 @@ import Form from './components/Form'
1414
class Page extends Component {
1515
// set name of the component
1616
static displayName = 'LoginPage'
17-
17+
1818
// validate props
1919
static propTypes = {
2020
isAuthenticated: PropTypes.bool.isRequired,
2121
dispatch: PropTypes.func.isRequired
2222
}
23-
23+
2424
constructor(props) {
2525
super(props)
26-
26+
2727
this.validator = new Validator({
2828
email: 'required|email',
2929
password: 'required|min:6'
3030
})
31-
31+
3232
// set the state of the app
3333
this.state = {
3434
credentials: {
@@ -38,42 +38,42 @@ class Page extends Component {
3838
},
3939
errors: this.validator.errors
4040
}
41-
41+
4242
// bind component with event handlers
4343
this.handleChange = this.handleChange.bind(this)
4444
this.handleSubmit = this.handleSubmit.bind(this)
4545
}
46-
46+
4747
// after mounting the component add a style to the body
4848
componentDidMount() {
4949
$('body').attr('style', 'background-color: #eee')
5050
}
51-
51+
5252
// remove body style before component leaves dom
5353
componentWillUnmount() {
5454
$('body').removeAttr('style')
5555
}
56-
56+
5757
// event to handle input change
5858
handleChange(name, value) {
5959
const { errors } = this.validator
60-
60+
6161
this.setState({ credentials: { ...this.state.credentials, [name]: value } })
62-
62+
6363
errors.remove(name)
64-
64+
6565
this.validator.validate(name, value)
6666
.then(() => {
6767
this.setState({ errors })
6868
})
6969
}
70-
70+
7171
// event to handle form submit
7272
handleSubmit(e) {
7373
e.preventDefault()
7474
const { credentials } = this.state
7575
const { errors } = this.validator
76-
76+
7777
this.validator.validateAll(credentials)
7878
.then((success) => {
7979
if (success) {
@@ -83,27 +83,27 @@ class Page extends Component {
8383
}
8484
})
8585
}
86-
86+
8787
submit(credentials) {
8888
this.props.dispatch(login(credentials))
8989
.catch(({ error, statusCode }) => {
9090
const { errors } = this.validator
91-
91+
9292
if (statusCode === 422) {
9393
_.forOwn(error, (message, field) => {
9494
errors.add(field, message);
9595
});
9696
} else if (statusCode === 401) {
9797
errors.add('password', error);
9898
}
99-
99+
100100
this.setState({ errors })
101101
})
102102
}
103-
103+
104104
// render component
105105
render() {
106-
106+
107107
// check if user is authenticated then redirect him to home page
108108
if (this.props.isAuthenticated) {
109109
return <Redirect to="/" />
@@ -116,7 +116,7 @@ class Page extends Component {
116116
handleChange: this.handleChange,
117117
handleSubmit: this.handleSubmit,
118118
}
119-
119+
120120
return (<div className="container py-5">
121121
<div className="row">
122122
<div className="col-md-12">

resources/assets/js/pages/register/Page.js renamed to resources/assets/js/modules/auth/pages/register/Page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
44
import $ from 'jquery'
55
import _ from 'lodash'
66
import { Redirect } from 'react-router-dom'
7-
import { register } from '../../store/services/auth'
7+
import { register } from '../../service'
88
import { Validator } from 'ree-validate'
99

1010
// import components
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Register from "./pages/register"
2+
import Login from "./pages/login"
3+
4+
export default [
5+
{
6+
path: '/login',
7+
exact: true,
8+
component: Login,
9+
},
10+
{
11+
path: '/register',
12+
exact: true,
13+
component: Register,
14+
},
15+
]

0 commit comments

Comments
 (0)