


npm install firebase// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
// 初始化firebase的配置信息
const firebaseConfig = {
apiKey: "AIzaSyBoayOSkMauSE0rq6vj4NzfsT75tWviJY0",
authDomain: "test-csdn.firebaseapp.com",
projectId: "test-csdn",
storageBucket: "test-csdn.appspot.com",
messagingSenderId: "356839085174",
appId: "1:356836085174:web:bd0ad1246d767ffce4fa57",
measurementId: "G-37QBHYS56N"
};
// Initialize Firebase (初始化 firebase ,这一步必须走!)
const app = initializeApp(firebaseConfig);
import { GoogleAuthProvider } from "firebase/auth";
const provider = new GoogleAuthProvider();
import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";
const auth = getAuth();
signInWithPopup(auth, provider)
.then((result) => {
// This gives you a Google Access Token. You can use it to access the Google API.
const credential = GoogleAuthProvider.credentialFromResult(result);
// 用户token
const token = credential.accessToken;
// 用户登录后所获得的信息 The signed-in user info.
const user = result.user;
// IdP data available using getAdditionalUserInfo(result)
// ...
}).catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.customData.email;
// The AuthCredential type that was used.
const credential = GoogleAuthProvider.credentialFromError(error);
// ...
});




facebook第三方登录需要到 facebook的后台管理系统配置流程。facebook开发者官网链接
创建自己的应用(流程跟着官网走就行了),然后准备这个界面(应用编号和应用密钥)

到firebase上增加允许facebook登录

在这里填写facebook的应用编码和应用密钥。

最关键的一步:复制firebase中的OAuth(上图密钥下面那个地址:https://test-85788.firebaseapp.com/__/auth/handler),然后配置到facebook中的重定向OAuth,所在位置看下图


完成上面步骤后打包至测试服地址或者线上测试!facebook登录不支持 http 协议。
意味着线下无法测试facebook登录)!