Skip to content

Commit 2f3b1a0

Browse files
Updating app to redirect to homepage once signed in
1 parent 340e09d commit 2f3b1a0

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

src/App.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { Component } from 'react';
22
import { connect } from 'react-redux'
33
import './App.css';
4-
import { Route, Switch } from 'react-router-dom';
4+
import { Route, Switch, Redirect } from 'react-router-dom';
55
import Homepage from './Pages/homepage/Homepage.component'
66
import ShopPage from './Pages/shop/Shop.component'
7-
import signInAndSignUpPage from './Pages/sign-in-and-sign-up/sign-in-and-sign-up.component'
7+
import SignInAndSignUpPage from './Pages/sign-in-and-sign-up/sign-in-and-sign-up.component'
88
import Header from './components/header/header.component'
99
import { auth, createUserProfileDocument } from './firebase/firebase.utils'
1010
import { setCurrentUser } from './redux/user/user.actions'
@@ -39,13 +39,16 @@ class App extends Component {
3939
<Switch>
4040
<Route exact path='/' component={Homepage} />
4141
<Route exact path='/shop' component={ShopPage} />
42-
<Route exact path='/signin' component={signInAndSignUpPage} />
42+
<Route exact path='/signin' render={() => this.props.currentUser ? (<Redirect to='/' />) : <SignInAndSignUpPage />} />
4343
</Switch>
4444
</div>;
4545
}
4646
}
47+
const mapStateToProps = ({ user }) => ({
48+
currentUser: user.currentUser
49+
})
4750

4851
const mapDispatchToProps = dispatch => ({
4952
setCurrentUser: user => dispatch(setCurrentUser(user))
5053
})
51-
export default connect(null, mapDispatchToProps)(App);
54+
export default connect(mapStateToProps, mapDispatchToProps)(App);

src/Pages/sign-in-and-sign-up/sign-in-and-sign-up.component.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import './sign-in-and-sign-up.styles.scss'
33
import SignInForm from '../../components/sign-in/sign-in.component'
44
import SignUpForm from '../../components/sign-up/sign-up.component'
5-
export default function signInAndSignUpPage() {
5+
export default function SignInAndSignUpPage() {
66
return (
77
<div className="sign-in-and-sign-up">
88
<SignInForm />

src/redux/user/user.actions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
import { UserActionTypes } from './user.types'
12
export const setCurrentUser = user => ({
2-
type: 'SET_CURRENT_USER',
3+
type: UserActionTypes.SET_CURRENT_USER,
34
payload: user
45
})

src/redux/user/user.reducer.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import { UserActionTypes } from './user.types'
2+
3+
4+
15
const INITIAL_STATE = {
26
currentUser: null
37
}
48
const userReducer = (state = INITIAL_STATE, action) => {
5-
switch(action.type){
6-
case "SET_CURRENT_USER":
9+
switch (action.type) {
10+
case UserActionTypes.SET_CURRENT_USER:
711
return {
812
...state,
913
currentUser: action.payload

src/redux/user/user.types.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const UserActionTypes = {
2+
SET_CURRENT_USER: "SET_CURRENT_USER"
3+
}

0 commit comments

Comments
 (0)