-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
firebase upgrade to version 9.*.* #1406
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
import firebase, { logout, loginGitHub } from '../lib/client' | ||
import { getApps } from 'firebase/app' | ||
import { logout, loginGitHub } from '../lib/client' | ||
|
||
import Button from './Button' | ||
import Popout, { managePopout } from './Popout' | ||
|
@@ -48,7 +49,7 @@ function Drawer(props) { | |
function LoginButton({ isVisible, toggleVisibility }) { | ||
const user = useAuth() | ||
|
||
if (!firebase) { | ||
if (getApps().length === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we make the other change suggested below, we don't need to make this change |
||
return null | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,48 @@ | ||
import firebase from 'firebase/app' | ||
import 'firebase/auth' | ||
|
||
if (firebase.apps.length === 0) { | ||
if (process.env.NEXT_PUBLIC_FIREBASE_API_KEY && process.env.NEXT_PUBLIC_FIREBASE_FE_APP_ID) { | ||
firebase.initializeApp({ | ||
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY, | ||
authDomain: `${process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID}.firebaseapp.com`, | ||
databaseURL: `https://${process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID}.firebaseio.com`, | ||
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID, | ||
storageBucket: `${process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID}.appspot.com`, | ||
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID, | ||
appId: process.env.NEXT_PUBLIC_FIREBASE_FE_APP_ID, | ||
}) | ||
} | ||
import { getApps, initializeApp } from "firebase/app"; | ||
import { getAuth, signOut , setPersistence , browserLocalPersistence , signInWithPopup , GithubAuthProvider , onAuthStateChanged} from 'firebase/auth'; | ||
|
||
|
||
const firebaseConfig = { | ||
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY, | ||
authDomain: `${process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID}.firebaseapp.com`, | ||
databaseURL: `https://${process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID}.firebaseio.com`, | ||
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID, | ||
storageBucket: `${process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID}.appspot.com`, | ||
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID, | ||
appId: process.env.NEXT_PUBLIC_FIREBASE_FE_APP_ID, | ||
}; | ||
|
||
let FirebaseApp , auth | ||
|
||
if(getApps().length === 0 ) | ||
{ | ||
if(typeof process.env.NEXT_PUBLIC_FIREBASE_API_KEY !== "undefined" && typeof process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID !== "undefined" ) | ||
{ | ||
FirebaseApp = initializeApp(firebaseConfig) | ||
auth = getAuth(FirebaseApp) | ||
} | ||
} | ||
|
||
export function logout() { | ||
return firebase.auth().signOut().catch(console.error) | ||
return signOut(auth).then(() => { | ||
// Sign out successful | ||
}).catch((error) => { | ||
console.log(error) | ||
}); | ||
} | ||
|
||
export function login(provider) { | ||
return firebase | ||
.auth() | ||
.setPersistence(firebase.auth.Auth.Persistence.LOCAL) | ||
.then(() => firebase.auth().signInWithPopup(provider)) | ||
return setPersistence(auth, browserLocalPersistence) | ||
.then(() => signInWithPopup(auth, provider)) | ||
.catch(console.error) | ||
} | ||
|
||
export function loginGitHub() { | ||
const provider = new firebase.auth.GithubAuthProvider() | ||
const provider = new GithubAuthProvider() | ||
provider.setCustomParameters({ | ||
allow_signup: 'true', | ||
}) | ||
return login(provider) | ||
} | ||
|
||
export default firebase.apps.length ? firebase : null | ||
export default FirebaseApp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we still make this: getApps().length ? firebase : null so that we don't need to call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as below.