Home

Firebase Auth

Learn how to interact with Firebase

Firebase is a development platform from Google that provides a variety of tools and services to help developers build, improve, and grow their apps, with features such as databases, analytics, messaging, and crash reporting. It emphasizes easy integration and real-time updates, enabling developers to create rich, collaborative experiences.

Prerequisites#

Head to your Project Settings in the Firebase Console and grab your Firebase Project ID.

Set up your provider#

To set up Firebase to authenticate players with Openfort, visit your dashboard provider settings.

firebase auth

Client-side Integration#


_14
import {GoogleAuthProvider, getAuth, signInWithPopup} from "firebase/auth";
_14
import Openfort from "@openfort/openfort-js";
_14
_14
function loginWithGoogle() {
_14
const googleProvider = new GoogleAuthProvider();
_14
_14
signInWithPopup(auth, googleProvider)
_14
.then(async (result) => {
_14
const idToken = await result.user.getIdToken();
_14
const openfort = new Openfort(process.env.NEXT_PUBLIC_OPENFORT_PUBLIC_KEY!);
_14
_14
const token = await openfort.authenticateWithThirdPartyProvider("firebase", idToken, TokenType.IdToken);
_14
})
_14
}

Uppon successful authentication, the SDK will return:

response.json

_12
{
_12
"id": "pla_cc9ed2b7-c5f5-4c43-8dca-c4b104ba1762",
_12
"object": "player",
_12
"createdAt": 1710976453,
_12
"linkedAccounts": [
_12
{
_12
"provider": "firebase",
_12
"disabled": false,
_12
"externalUserId": "2"
_12
}
_12
]
_12
}

Example#

Resources#