Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace outdated react-firebaseui package #694

Merged
merged 9 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion example/components/FirebaseAuth.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* globals window */
import React, { useEffect, useState } from 'react'
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth'
import { getApp } from 'firebase/app'
import { getAuth, EmailAuthProvider } from 'firebase/auth'
import StyledFirebaseAuth from './StyledFirebaseAuth'

// Note that next-firebase-auth inits Firebase for us,
// so we don't need to.
Expand Down
69 changes: 69 additions & 0 deletions example/components/StyledFirebaseAuth.tsx
MvRemmerden marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { useEffect, useRef, useState } from 'react'
import { onAuthStateChanged } from 'firebase/auth'
import 'firebaseui/dist/firebaseui.css'
import { auth } from 'firebaseui'

interface Props {
// The Firebase UI Web UI Config object.
// See: https://github.com/firebase/firebaseui-web#configuration
uiConfig: auth.Config
// Callback that will be passed the FirebaseUi instance before it is
// started. This allows access to certain configuration options such as
// disableAutoSignIn().
uiCallback?(ui: auth.AuthUI): void

Check failure on line 13 in example/components/StyledFirebaseAuth.tsx

View workflow job for this annotation

GitHub Actions / build

propType "uiCallback" is not required, but has no corresponding defaultProps declaration
// The Firebase App auth instance to use.
firebaseAuth: any // As firebaseui-web

Check failure on line 15 in example/components/StyledFirebaseAuth.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
className?: string

Check failure on line 16 in example/components/StyledFirebaseAuth.tsx

View workflow job for this annotation

GitHub Actions / build

propType "className" is not required, but has no corresponding defaultProps declaration
}
MvRemmerden marked this conversation as resolved.
Show resolved Hide resolved

const StyledFirebaseAuth = ({
uiConfig,
firebaseAuth,
className,
uiCallback,
}: Props) => {
const [firebaseui, setFirebaseui] = useState<
typeof import('firebaseui') | null
>(null)
const [userSignedIn, setUserSignedIn] = useState(false)
const elementRef = useRef(null)

useEffect(() => {
// Firebase UI only works on the Client. So we're loading the package only after
// the component has mounted, so that this works when doing server-side rendering.
setFirebaseui(require('firebaseui'))

Check failure on line 34 in example/components/StyledFirebaseAuth.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected require()

Check failure on line 34 in example/components/StyledFirebaseAuth.tsx

View workflow job for this annotation

GitHub Actions / build

Require statement not part of import statement
}, [])

useEffect(() => {
if (firebaseui === null) return

// Get or Create a firebaseUI instance.
const firebaseUiWidget =
firebaseui.auth.AuthUI.getInstance() ||
new firebaseui.auth.AuthUI(firebaseAuth)
if (uiConfig.signInFlow === 'popup') firebaseUiWidget.reset()

// We track the auth state to reset firebaseUi if the user signs out.
const unregisterAuthObserver = onAuthStateChanged(firebaseAuth, (user) => {
if (!user && userSignedIn) firebaseUiWidget.reset()
setUserSignedIn(!!user)
})

// Trigger the callback if any was set.
if (uiCallback) uiCallback(firebaseUiWidget)

// Render the firebaseUi Widget.
// @ts-ignore

Check failure on line 56 in example/components/StyledFirebaseAuth.tsx

View workflow job for this annotation

GitHub Actions / build

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
firebaseUiWidget.start(elementRef.current, uiConfig)

return () => {

Check failure on line 59 in example/components/StyledFirebaseAuth.tsx

View workflow job for this annotation

GitHub Actions / build

Arrow function expected no return value
unregisterAuthObserver()
firebaseUiWidget.reset()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [firebaseui, uiConfig])

return <div className={className} ref={elementRef} />

Check failure on line 66 in example/components/StyledFirebaseAuth.tsx

View workflow job for this annotation

GitHub Actions / build

'React' must be in scope when using JSX
}

export default StyledFirebaseAuth
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"dependencies": {
"firebase": "9.17.1",
"firebase-admin": "^11.9.0",
"firebaseui": "^6.1.0",
"next": "13.4.9",
"next-absolute-url": "^1.2.2",
"next-firebase-auth": "1.0.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-firebaseui": "^6.0.0"
"react-dom": "18.2.0"
},
"devDependencies": {
"@next/bundle-analyzer": "^13.4.9",
Expand All @@ -25,4 +25,4 @@
"eslint-config-next": "^13.4.9",
"typescript": "^5.1.6"
}
}
}
Loading
Loading