Skip to content
Prev Previous commit
Next Next commit
Auto profile population removed
* Auto profile population removed (profile population will require
using populate)
* Firebase JSON Auth Error fixed by commenting out router decorators
(more investigation needed for v2.0.0)
  • Loading branch information
prescottprue committed Jul 3, 2017
commit 90ebcb64ebf2dba88418cc240da1ab32840494e7
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ import {
import Paper from 'material-ui/Paper'
import Snackbar from 'material-ui/Snackbar'
import { UserIsNotAuthenticated } from 'utils/router'
import { SIGNUP_PATH } from 'constants'
import { SIGNUP_PATH, LIST_PATH } from 'constants'
import LoginForm from '../components/LoginForm'
import classes from './LoginContainer.scss'

@UserIsNotAuthenticated // redirect to list page if logged in
// TODO: Uncomment redirect decorator v2.0.0 router util still requires update
// @UserIsNotAuthenticated // redirect to list page if logged in
@firebaseConnect() // add this.props.firebase
@connect( // map redux state to props
({ firebase: { authError } }) => ({
authError
})
)
export default class Login extends Component {
static contextTypes = {
router: PropTypes.object.isRequired
}

static propTypes = {
firebase: PropTypes.shape({
login: PropTypes.func.isRequired
Expand All @@ -40,6 +45,9 @@ export default class Login extends Component {
handleLogin = loginData => {
this.setState({ snackCanOpen: true })
return this.props.firebase.login(loginData)
.then(() => {
return this.context.router.push(LIST_PATH) // v2.0.0 router util still requires update
})
}

providerLogin = (provider) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ import {
} from 'react-redux-firebase'
import Paper from 'material-ui/Paper'
import Snackbar from 'material-ui/Snackbar'
import { LOGIN_PATH } from 'constants'
import { LOGIN_PATH, LIST_PATH } from 'constants'
import { UserIsNotAuthenticated } from 'utils/router'
import SignupForm from '../components/SignupForm'
import classes from './SignupContainer.scss'

@UserIsNotAuthenticated // redirect to list page if logged in
// TODO: Uncomment redirect decorator v2.0.0 router util still requires update
// @UserIsNotAuthenticated // redirect to list page if logged in
@firebaseConnect() // add this.props.firebase
@connect( // map redux state to props
({firebase}) => ({
authError: pathToJS(firebase, 'authError')
})
)
export default class Signup extends Component {
static contextTypes = {
router: PropTypes.object.isRequired
}

static propTypes = {
firebase: PropTypes.object,
authError: PropTypes.object
Expand All @@ -40,6 +45,9 @@ export default class Signup extends Component {
// create new user then login (redirect handled by decorator)
return createUser(creds, { email, username })
.then(() => login(creds))
.then(() => {
return this.context.router.push(LIST_PATH) // v2.0.0 router util still requires update
})
}

providerLogin = (provider) => {
Expand Down
82 changes: 16 additions & 66 deletions src/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ import {
isArray,
isString,
isFunction,
forEach,
set,
get,
map,
mapValues
forEach
} from 'lodash'
import { actionTypes, defaultJWTProps } from '../constants'
import { getLoginMethodAndParams } from '../utils/auth'
import {
promisesForPopulate,
getPopulateObjs,
getChildType
} from '../utils/populate'
import { promisesForPopulate } from '../utils/populate'

/**
* @description Dispatch login error action
Expand Down Expand Up @@ -65,8 +57,7 @@ export const watchUserProfile = (dispatch, firebase) => {
.on('value', snap => {
const {
profileParamsToPopulate,
autoPopulateProfile,
setProfilePopulateResults
autoPopulateProfile
} = firebase._.config
if (!profileParamsToPopulate || (!isArray(profileParamsToPopulate) && !isString(profileParamsToPopulate))) {
dispatch({ type: actionTypes.SET_PROFILE, profile: snap.val() })
Expand All @@ -75,63 +66,22 @@ export const watchUserProfile = (dispatch, firebase) => {
// Convert each populate string in array into an array of once query promises
promisesForPopulate(firebase, snap.val(), profileParamsToPopulate)
.then(data => {
// Fire actions for placement of data gathered in populate into redux
forEach(data, (result, path) => {
dispatch({
type: actionTypes.SET,
path,
data: result,
timestamp: Date.now(),
requesting: false,
requested: true
})
})
dispatch({ type: actionTypes.SET_PROFILE, profile: snap.val() })
// Dispatch action with profile combined with populated parameters
// Auto Populate profile
if (autoPopulateProfile) {
const populates = getPopulateObjs(profileParamsToPopulate)
const profile = snap.val()
forEach(populates, (p) => {
const child = get(profile, p.child)
const childType = getChildType(child)
let populatedChild

switch (childType) {
case 'object':
populatedChild = mapValues(
child,
(value, key) => {
if (value) { // Only populate keys with truthy values
return get(data, `${p.root}.${key}`)
}
return value
})
break

case 'string':
populatedChild = get(data, `${p.root}.${child}`)
break

case 'array':
populatedChild = map(
child,
(key) => get(data, `${p.root}.${key}`)
)
break

default:
populatedChild = child
}
// Overwrite the child value with the populated child
set(profile, p.child, populatedChild)
})
dispatch({ type: actionTypes.SET_PROFILE, profile })
} else {
// dispatch with unpopulated profile data
dispatch({ type: actionTypes.SET_PROFILE, profile: snap.val() })
}

// Fire actions for placement of data gathered in populate into redux
if (setProfilePopulateResults) {
forEach(data, (result, path) => {
dispatch({
type: actionTypes.SET,
path,
data: result,
timestamp: Date.now(),
requesting: false,
requested: true
})
})
console.warn('Auto populate is no longer supported. We are working on backwards compatibility for v2.0.0') // eslint-disable-line no-console
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const actionTypes = {
* empty auth changes such as `undefined` on initialization
* (see [#137](https://github.com/prescottprue/react-redux-firebase/issues/137)).
* Requires `v1.5.0-alpha` or higher.
* @property {Boolean} autoPopulateProfile - `true` Whether or not to
* @property {Boolean} autoPopulateProfile - `false` REMOVED FROM v2.0.0. Whether or not to
* automatically populate profile with data loaded through
* profileParamsToPopulate config.
* @property {Boolean} setProfilePopulateResults - `true` Whether or not to
Expand All @@ -123,7 +123,7 @@ export const defaultConfig = {
enableLogging: false,
updateProfileOnLogin: true,
enableRedirectHandling: true,
autoPopulateProfile: true,
autoPopulateProfile: false,
setProfilePopulateResults: false,
dispatchOnUnsetListener: true,
enableEmptyAuthChanges: false
Expand Down