Skip to content

Commit

Permalink
v0.9.4
Browse files Browse the repository at this point in the history
* fix(app): add back logic for adding account on first login
* chore(app): prevent infinite reloading on local when version is changed
  • Loading branch information
prescottprue committed May 28, 2020
1 parent 71f025e commit 8ecb470
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fireadmin",
"version": "0.9.3",
"version": "0.9.4",
"description": "Application for Managing Firebase Applications. Includes support for multiple environments and data migrations.",
"scripts": {
"clean": "rimraf build",
Expand Down
7 changes: 6 additions & 1 deletion src/components/VersionChangeReloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export default function VersionChangeReloader() {
const refreshHasOccurred = currentRemoteVersion === sessionVersion

// Refresh if session contains different version than database
if (versionDiscrepencyExists && !refreshHasOccurred) {
if (
versionDiscrepencyExists &&
!refreshHasOccurred &&
// refresh not enabled locally since DB update happens in deploy
!window.location.host.includes('localhost')
) {
window.location.reload(true)
}
}, [versionInfo])
Expand Down
53 changes: 43 additions & 10 deletions src/routes/Login/components/LoginPage/LoginPage.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,72 @@
import React, { useState } from 'react'
import firebase from 'firebase/app' // imported for auth provider
import { useAuth } from 'reactfire'
import { useAuth, useFirestore } from 'reactfire'
import GoogleButton from 'react-google-button'
import { makeStyles } from '@material-ui/core/styles'
import Container from '@material-ui/core/Container'
import Paper from '@material-ui/core/Paper'
import Typography from '@material-ui/core/Typography'
import * as Sentry from '@sentry/browser'
import { USERS_COLLECTION } from 'constants/firebasePaths'
import useNotifications from 'modules/notification/useNotifications'
import { LIST_PATH } from 'constants/paths'
import LoadingSpinner from 'components/LoadingSpinner'
import styles from './LoginPage.styles'
import { Typography } from '@material-ui/core'

const useStyles = makeStyles(styles)

function LoginPage() {
const classes = useStyles()
const auth = useAuth()
const firestore = useFirestore()
const { showError } = useNotifications()
const [isLoading, changeLoadingState] = useState(false)

function googleLogin() {
async function googleLogin() {
const provider = new firebase.auth.GoogleAuthProvider()
changeLoadingState(true)
const authMethod =
window.isMobile && window.isMobile.any
? 'signInWithRedirect'
: 'signInWithPopup'
let authData
try {
authData = await auth[authMethod](provider)
} catch (err) {
console.error('Error with login:', err) // eslint-disable-line no-console
showError(err.message)
Sentry.captureException(err)
}

return auth[authMethod](provider)
.then(() => {
// NOTE: history.push sometimes does not trigger
// history.push(LIST_PATH)
window.location = LIST_PATH
})
.catch((err) => showError(err.message))
try {
// Load user account to see if it exists
const userSnap = await firestore
.doc(`${USERS_COLLECTION}/${authData.user.uid}`)
.get()
// Save new user account if it doesn't already exist
if (!userSnap.exists) {
const {
email,
displayName,
providerData,
lastLoginAt
} = authData.user.toJSON()
const userObject = { email, displayName, lastLoginAt }
if (providerData) {
userObject.providerData = providerData
}
await firestore
.doc(`${USERS_COLLECTION}/${authData.user.uid}`)
.set(userObject, { merge: true })
}
// NOTE: history.push sometimes does not trigger
// history.push(LIST_PATH)
window.location = LIST_PATH
} catch (err) {
console.error('Error setting user profile:', err) // eslint-disable-line no-console
showError(err.message)
Sentry.captureException(err)
}
}

return (
Expand Down

0 comments on commit 8ecb470

Please sign in to comment.