From d5593158664bfed971184c3f7914e8713e9cbe17 Mon Sep 17 00:00:00 2001 From: artem ash Date: Tue, 12 Nov 2024 16:15:20 -0800 Subject: [PATCH] Minor fix to @hanzo/auth for noAuth version; minor typescript issues --- pkg/auth/components/auth-widget.tsx | 40 ++++++++++++++--------------- pkg/auth/package.json | 2 +- pkg/auth/server/firebase-support.ts | 8 +++--- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/pkg/auth/components/auth-widget.tsx b/pkg/auth/components/auth-widget.tsx index 1c1a1f2a..df4d8ef6 100644 --- a/pkg/auth/components/auth-widget.tsx +++ b/pkg/auth/components/auth-widget.tsx @@ -42,7 +42,7 @@ const AuthWidget: React.FC<{ // the root in host mono repos, but this is another layer. // Also, this allows sites to opt-in to showing an auth widget without // configuration, by just providing the context. - if (!auth) { + if (!auth || noLogin) { return null } @@ -50,26 +50,24 @@ const AuthWidget: React.FC<{ // button regardless of status. if (!auth.loggedIn && typeof window !== 'undefined') { - return (noLogin ? null : ( - (handleLogin) ? ( - - ) : ( - - ) + return (handleLogin ? ( + + ) : ( + )) } diff --git a/pkg/auth/package.json b/pkg/auth/package.json index e233bd95..e07073fc 100644 --- a/pkg/auth/package.json +++ b/pkg/auth/package.json @@ -1,6 +1,6 @@ { "name": "@hanzo/auth", - "version": "2.5.1", + "version": "2.5.2", "description": "Library with Firebase authentication.", "publishConfig": { "registry": "https://registry.npmjs.org/", diff --git a/pkg/auth/server/firebase-support.ts b/pkg/auth/server/firebase-support.ts index 9275273e..2b9f2e35 100644 --- a/pkg/auth/server/firebase-support.ts +++ b/pkg/auth/server/firebase-support.ts @@ -1,14 +1,14 @@ import 'server-only' import { cookies } from 'next/headers' -import { initializeApp, getApps, cert } from 'firebase-admin/app' +import { initializeApp, getApps, cert, type App } from 'firebase-admin/app' import { type SessionCookieOptions, type UserRecord, getAuth } from 'firebase-admin/auth' import { collection, doc, getDoc, setDoc } from 'firebase/firestore' import { getFirestore } from 'firebase-admin/firestore' import type { HanzoUserInfo, HanzoUserInfoValue } from '../types' // Initialize Firebase only if credentials are present and valid -let firebaseApp; +let firebaseApp: App | undefined; try { const hasValidCredentials = process.env.FIREBASE_CLIENT_EMAIL && process.env.FIREBASE_PROJECT_ID && process.env.FIREBASE_PRIVATE_KEY; @@ -30,13 +30,13 @@ try { } } catch (error) { console.error('Failed to initialize Firebase Admin SDK:', error); - firebaseApp = null; + firebaseApp = undefined; } const USER_INFO_COLLECTION = 'USER_INFO' const auth = getAuth(firebaseApp) -const db = getFirestore(firebaseApp, 'accounts') +const db = getFirestore(firebaseApp as App, 'accounts') async function isUserAuthenticated(session: string | undefined = undefined) { const _session = session ?? (await getSession())