Skip to content

Commit

Permalink
Replace outdated react-firebaseui package
Browse files Browse the repository at this point in the history
  • Loading branch information
MvRemmerden committed Dec 3, 2023
1 parent 44475f8 commit 73ba363
Show file tree
Hide file tree
Showing 5 changed files with 7,749 additions and 617 deletions.
2 changes: 1 addition & 1 deletion example/components/FirebaseAuth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals window */
import React, { useEffect, useState } from 'react'
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth'
import StyledFirebaseAuth from './StyledFirebaseAuth'

Check failure on line 3 in example/components/FirebaseAuth.js

View workflow job for this annotation

GitHub Actions / build

`./StyledFirebaseAuth` import should occur after import of `firebase/auth`
import { getApp } from 'firebase/app'
import { getAuth, EmailAuthProvider } from 'firebase/auth'

Expand Down
66 changes: 66 additions & 0 deletions example/components/StyledFirebaseAuth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { useEffect, useRef, useState } from 'react';

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

View workflow job for this annotation

GitHub Actions / build

Delete `;`
import { onAuthStateChanged } from 'firebase/auth';

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

View workflow job for this annotation

GitHub Actions / build

Delete `;`
import 'firebaseui/dist/firebaseui.css';

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

View workflow job for this annotation

GitHub Actions / build

Delete `;`
import {auth} from "firebaseui";

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

View workflow job for this annotation

GitHub Actions / build

Replace `auth}·from·"firebaseui";` with `·auth·}·from·'firebaseui'`

interface Props {
// The Firebase UI Web UI Config object.

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

View workflow job for this annotation

GitHub Actions / build

Delete `··`
// See: https://github.com/firebase/firebaseui-web#configuration

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

View workflow job for this annotation

GitHub Actions / build

Delete `··`
uiConfig: auth.Config;

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

View workflow job for this annotation

GitHub Actions / build

Replace `····uiConfig:·auth.Config;` with `··uiConfig:·auth.Config`
// Callback that will be passed the FirebaseUi instance before it is

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

View workflow job for this annotation

GitHub Actions / build

Delete `··`
// started. This allows access to certain configuration options such as

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

View workflow job for this annotation

GitHub Actions / build

Replace `····` with `··`
// disableAutoSignIn().
uiCallback?(ui: auth.AuthUI): void;
// The Firebase App auth instance to use.
firebaseAuth: any; // As firebaseui-web

Check warning 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;
}


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'));
}, []);


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
firebaseUiWidget.start(elementRef.current, uiConfig);

return () => {
unregisterAuthObserver();
firebaseUiWidget.reset();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [firebaseui, uiConfig]);

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

export default StyledFirebaseAuth;
Loading

0 comments on commit 73ba363

Please sign in to comment.