This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

fix profile link

+57 -2
+57 -2
src/components/NavigationBar.tsx
··· 1 1 'use client'; 2 2 3 - import React from 'react'; 3 + import React, { useState, useEffect } from 'react'; 4 4 import Link from 'next/link'; 5 5 import Image from 'next/image'; 6 6 import { usePathname } from 'next/navigation'; ··· 12 12 export default function NavigationBar() { 13 13 const pathname = usePathname(); 14 14 const { isAuthenticated, signOut, session } = useAuth(); 15 - const handle = null; // Will be fetched when needed 15 + const [handle, setHandle] = useState<string | null>(null); 16 + 17 + // Fetch user's handle when authenticated 18 + useEffect(() => { 19 + if (isAuthenticated && session?.sub && !handle) { 20 + fetchUserHandle(session.sub); 21 + } 22 + }, [isAuthenticated, session?.sub, handle]); 23 + 24 + const fetchUserHandle = async (did: string) => { 25 + try { 26 + // Try to resolve DID to handle using PLC directory 27 + const plcResponse = await fetch(`https://plc.directory/${did}/data`); 28 + 29 + if (plcResponse.ok) { 30 + const plcData = await plcResponse.json(); 31 + if (plcData.alsoKnownAs && plcData.alsoKnownAs.length > 0) { 32 + const handleUrl = plcData.alsoKnownAs[0]; 33 + if (handleUrl.startsWith('at://')) { 34 + const userHandle = handleUrl.substring(5); // Remove 'at://' 35 + console.log(`Resolved DID ${did} to handle ${userHandle}`); 36 + setHandle(userHandle); 37 + return; 38 + } 39 + } 40 + } 41 + } catch (error) { 42 + console.warn('Failed to resolve handle from PLC directory:', error); 43 + } 44 + 45 + // Fallback: try using the profile API 46 + try { 47 + const response = await fetch('/api/bluesky/profile', { 48 + method: 'POST', 49 + headers: { 50 + 'Content-Type': 'application/json' 51 + }, 52 + body: JSON.stringify({ 53 + accessToken: 'placeholder', // OAuth session handles auth internally 54 + dpopToken: 'placeholder', // OAuth session handles auth internally 55 + handle: did, 56 + pdsEndpoint: null 57 + }) 58 + }); 59 + 60 + if (response.ok) { 61 + const data = await response.json(); 62 + if (data.handle && data.handle !== 'unknown') { 63 + setHandle(data.handle); 64 + } 65 + } 66 + } catch (error) { 67 + console.warn('Failed to fetch handle from profile API:', error); 68 + } 69 + }; 16 70 17 71 const handleLogout = async () => { 18 72 await signOut(); 73 + setHandle(null); // Clear handle on logout 19 74 }; 20 75 21 76 // Check if a link is active