Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions lib/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
convertToPlace,
getPersistenceMode,
isHomeOrWork,
isNewUser,
positionHomeAndWorkFirst,
setAtLeastNoMobilityDevice,
tidyRecentSearches
tidyRecentSearches,
userExistsInDatabase
} from '../util/user'
import {
formattedToastSuccessMessage,
Expand Down Expand Up @@ -391,7 +391,7 @@ export function createOrUpdateUser(userData, intl) {
)

// Determine URL and method to use.
const isCreatingUser = isNewUser(loggedInUser)
const isCreatingUser = userExistsInDatabase(loggedInUser)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the user entry in Mongo was meant to be created when they click "Next" after accepting the terms of use. I think you uncovered a bug that results in the user being created when they set the language and before they agree to the terms. Congrats!

To fix the bug:
In lib/actions/ui.js near line 471: replace

      if (loggedInUser) {

with

      if (!userNotInDatabase(loggedInUser)) {

(with correct import and corrected name/meaning.

if (isCreatingUser) {
requestUrl = `${apiBaseUrl}${API_OTPUSER_PATH}`
method = 'POST'
Expand Down
4 changes: 4 additions & 0 deletions lib/util/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function isNewUser(loggedInUser) {
return !loggedInUser.hasConsentedToTerms
}

export function userExistsInDatabase(loggedInUser) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean userDoesNotExistInDatabase or userNotInDatabase?

return !loggedInUser.id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loggedInUser might be null (after reloading the 'verify' page), so use the ?. optional chaining syntax.

}

// Helper functions to determine if
// a location is home or work.
export const isHome = (loc) => loc.type === 'home'
Expand Down
Loading