Skip to content

Commit

Permalink
Merge branch 'canary' into remove-babel-preset-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer authored Nov 4, 2020
2 parents 272c085 + 5ecdcab commit f3e8149
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
22 changes: 5 additions & 17 deletions examples/with-firebase-authentication/components/FirebaseAuth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* globals window */
import { useEffect, useState } from 'react'
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth'
import firebase from 'firebase/app'
import 'firebase/auth'
Expand All @@ -24,29 +22,19 @@ const firebaseAuthConfig = {
credentialHelper: 'none',
callbacks: {
signInSuccessWithAuthResult: async ({ user }, redirectUrl) => {
const userData = mapUserData(user)
const userData = await mapUserData(user)
setUserCookie(userData)
},
},
}

const FirebaseAuth = () => {
// Do not SSR FirebaseUI, because it is not supported.
// https://github.com/firebase/firebaseui-web/issues/213
const [renderAuth, setRenderAuth] = useState(false)
useEffect(() => {
if (typeof window !== 'undefined') {
setRenderAuth(true)
}
}, [])
return (
<div>
{renderAuth ? (
<StyledFirebaseAuth
uiConfig={firebaseAuthConfig}
firebaseAuth={firebase.auth()}
/>
) : null}
<StyledFirebaseAuth
uiConfig={firebaseAuthConfig}
firebaseAuth={firebase.auth()}
/>
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export const mapUserData = (user) => {
const { uid, email, xa, ya } = user
export const mapUserData = async (user) => {
const { uid, email } = user
const token = await user.getIdToken(true)
return {
id: uid,
email,
token: xa || ya,
token,
}
}
22 changes: 12 additions & 10 deletions examples/with-firebase-authentication/utils/auth/useUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ const useUser = () => {
// Firebase updates the id token every hour, this
// makes sure the react state and the cookie are
// both kept up to date
const cancelAuthListener = firebase.auth().onIdTokenChanged((user) => {
if (user) {
const userData = mapUserData(user)
setUserCookie(userData)
setUser(userData)
} else {
removeUserCookie()
setUser()
}
})
const cancelAuthListener = firebase
.auth()
.onIdTokenChanged(async (user) => {
if (user) {
const userData = await mapUserData(user)
setUserCookie(userData)
setUser(userData)
} else {
removeUserCookie()
setUser()
}
})

const userFromCookie = getUserFromCookie()
if (!userFromCookie) {
Expand Down
6 changes: 6 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"github": {
"silent": true,
"autoJobCancelation": true
}
}

0 comments on commit f3e8149

Please sign in to comment.