Skip to content

Commit 8ecb470

Browse files
committedMay 28, 2020
v0.9.4
* fix(app): add back logic for adding account on first login * chore(app): prevent infinite reloading on local when version is changed
·
v0.10.2v0.9.4
1 parent 71f025e commit 8ecb470

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed
 

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fireadmin",
3-
"version": "0.9.3",
3+
"version": "0.9.4",
44
"description": "Application for Managing Firebase Applications. Includes support for multiple environments and data migrations.",
55
"scripts": {
66
"clean": "rimraf build",

‎src/components/VersionChangeReloader/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ export default function VersionChangeReloader() {
3131
const refreshHasOccurred = currentRemoteVersion === sessionVersion
3232

3333
// Refresh if session contains different version than database
34-
if (versionDiscrepencyExists && !refreshHasOccurred) {
34+
if (
35+
versionDiscrepencyExists &&
36+
!refreshHasOccurred &&
37+
// refresh not enabled locally since DB update happens in deploy
38+
!window.location.host.includes('localhost')
39+
) {
3540
window.location.reload(true)
3641
}
3742
}, [versionInfo])

‎src/routes/Login/components/LoginPage/LoginPage.js

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,72 @@
11
import React, { useState } from 'react'
22
import firebase from 'firebase/app' // imported for auth provider
3-
import { useAuth } from 'reactfire'
3+
import { useAuth, useFirestore } from 'reactfire'
44
import GoogleButton from 'react-google-button'
55
import { makeStyles } from '@material-ui/core/styles'
66
import Container from '@material-ui/core/Container'
77
import Paper from '@material-ui/core/Paper'
8+
import Typography from '@material-ui/core/Typography'
9+
import * as Sentry from '@sentry/browser'
10+
import { USERS_COLLECTION } from 'constants/firebasePaths'
811
import useNotifications from 'modules/notification/useNotifications'
912
import { LIST_PATH } from 'constants/paths'
1013
import LoadingSpinner from 'components/LoadingSpinner'
1114
import styles from './LoginPage.styles'
12-
import { Typography } from '@material-ui/core'
1315

1416
const useStyles = makeStyles(styles)
1517

1618
function LoginPage() {
1719
const classes = useStyles()
1820
const auth = useAuth()
21+
const firestore = useFirestore()
1922
const { showError } = useNotifications()
2023
const [isLoading, changeLoadingState] = useState(false)
2124

22-
function googleLogin() {
25+
async function googleLogin() {
2326
const provider = new firebase.auth.GoogleAuthProvider()
2427
changeLoadingState(true)
2528
const authMethod =
2629
window.isMobile && window.isMobile.any
2730
? 'signInWithRedirect'
2831
: 'signInWithPopup'
32+
let authData
33+
try {
34+
authData = await auth[authMethod](provider)
35+
} catch (err) {
36+
console.error('Error with login:', err) // eslint-disable-line no-console
37+
showError(err.message)
38+
Sentry.captureException(err)
39+
}
2940

30-
return auth[authMethod](provider)
31-
.then(() => {
32-
// NOTE: history.push sometimes does not trigger
33-
// history.push(LIST_PATH)
34-
window.location = LIST_PATH
35-
})
36-
.catch((err) => showError(err.message))
41+
try {
42+
// Load user account to see if it exists
43+
const userSnap = await firestore
44+
.doc(`${USERS_COLLECTION}/${authData.user.uid}`)
45+
.get()
46+
// Save new user account if it doesn't already exist
47+
if (!userSnap.exists) {
48+
const {
49+
email,
50+
displayName,
51+
providerData,
52+
lastLoginAt
53+
} = authData.user.toJSON()
54+
const userObject = { email, displayName, lastLoginAt }
55+
if (providerData) {
56+
userObject.providerData = providerData
57+
}
58+
await firestore
59+
.doc(`${USERS_COLLECTION}/${authData.user.uid}`)
60+
.set(userObject, { merge: true })
61+
}
62+
// NOTE: history.push sometimes does not trigger
63+
// history.push(LIST_PATH)
64+
window.location = LIST_PATH
65+
} catch (err) {
66+
console.error('Error setting user profile:', err) // eslint-disable-line no-console
67+
showError(err.message)
68+
Sentry.captureException(err)
69+
}
3770
}
3871

3972
return (

0 commit comments

Comments
 (0)
Please sign in to comment.