Last active
November 4, 2024 19:35
-
-
Save jamesdaniels/8a9e7b65eb4f58f9e4f4ccdbc3f758d2 to your computer and use it in GitHub Desktop.
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
import "server-only"; | |
import { FirebaseServerApp, initializeServerApp } from 'firebase/app'; | |
import { getAuth } from "firebase/auth"; | |
import { FIREBASE_OPTIONS, COOKIE_NAME } from "./constants"; | |
import { cookies } from "next/headers"; | |
async function getServerApp() { | |
const authIdToken = (await cookies()).get(COOKIE_NAME)?.value; | |
return initializeServerApp(FIREBASE_OPTIONS, { authIdToken }); | |
} | |
export async function getServerAuth(app?: FirebaseServerApp) { | |
const serverApp = app || await getServerApp(); | |
const serverAuth = getAuth(serverApp); | |
await serverAuth.authStateReady(); | |
return serverAuth; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment