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 1 commit
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,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
MvRemmerden marked this conversation as resolved.
Show resolved Hide resolved
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;
}
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'));
}, []);


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
Loading