-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
446 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.