Skip to content

Commit

Permalink
Minor fix to @hanzo/auth for noAuth version;
Browse files Browse the repository at this point in the history
  minor typescript issues
  • Loading branch information
artemis-prime committed Nov 13, 2024
1 parent 4722617 commit d559315
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
40 changes: 19 additions & 21 deletions pkg/auth/components/auth-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,32 @@ 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
}

// If that is the case, the widget will always show the 'login'
// button regardless of status.
if (!auth.loggedIn && typeof window !== 'undefined') {

return (noLogin ? null : (
(handleLogin) ? (
<Button
variant='primary'
className='h-8 w-fit !min-w-0'
onClick={handleLogin}
>
Login
</Button>
) : (
<LinkElement
def={{
href: `${process.env.NEXT_PUBLIC_LOGIN_SITE_URL}?redirectUrl=${window.location.href}`,
title: 'Login',
variant: 'primary',
newTab: false
} satisfies LinkDef}
className='h-8 w-fit !min-w-0'
/>
)
return (handleLogin ? (
<Button
variant='primary'
className='h-8 w-fit !min-w-0'
onClick={handleLogin}
>
Login
</Button>
) : (
<LinkElement
def={{
href: `${process.env.NEXT_PUBLIC_LOGIN_SITE_URL}?redirectUrl=${window.location.href}`,
title: 'Login',
variant: 'primary',
newTab: false
} satisfies LinkDef}
className='h-8 w-fit !min-w-0'
/>
))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/package.json
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
8 changes: 4 additions & 4 deletions pkg/auth/server/firebase-support.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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())
Expand Down

0 comments on commit d559315

Please sign in to comment.