···155155 const getDisplayName = () => {
156156 if (!session) return '';
157157158158+ // First try displayName if available
159159+ if (session.displayName) {
160160+ return session.displayName;
161161+ }
162162+158163 // Try to get the handle from the session
159164 const handle = session.handle || '';
165165+ if (handle) {
166166+ return handle;
167167+ }
160168161161- // If it's a DID, show a shortened version
162162- if (session.sub.startsWith('did:')) {
163163- return session.sub.substring(0, 15) + '...';
169169+ // Try to get DID (could be in session.did or session.sub)
170170+ const did = session.did || session.sub;
171171+ if (did && did.startsWith('did:')) {
172172+ return did.substring(0, 15) + '...';
164173 }
165174166166- return handle;
175175+ // Fallback
176176+ return 'User';
167177 };
168178169179 return (
+99-8
src/contexts/AuthContext.js
···8181 const atprotoSession = localStorage.getItem('atproto_session');
8282 console.log('atproto_session in localStorage:', atprotoSession ? 'exists' : 'not found');
83838484+ // Try to extract handle from session
8585+ let handle = result.session.handle;
8686+8787+ // If handle is missing, try to extract it from other sources
8888+ if (!handle) {
8989+ try {
9090+ // Try server login data
9191+ if (result.session.server && result.session.server.login && result.session.server.login.handle) {
9292+ handle = result.session.server.login.handle;
9393+ }
9494+ // Try atproto_session in localStorage if it exists
9595+ else if (atprotoSession) {
9696+ try {
9797+ const parsedSession = JSON.parse(atprotoSession);
9898+ if (parsedSession && parsedSession.handle) {
9999+ handle = parsedSession.handle;
100100+ }
101101+ } catch (e) {
102102+ console.error('Error parsing atproto_session:', e);
103103+ }
104104+ }
105105+ } catch (e) {
106106+ console.error('Error extracting handle:', e);
107107+ }
108108+ }
109109+84110 // Format session data for our internal use and sync with server
85111 const sessionData = {
86112 did: result.session.sub,
8787- handle: result.session.handle
113113+ handle: handle || 'unknown' // Ensure we always have a handle value
88114 };
8911590116 console.log('Syncing session with server:', sessionData);
···107133 } else {
108134 console.warn('Initial session sync failed:', await syncResponse.text());
109135110110- // If sync fails, use client session in our internal format
111111- console.log('Using client session as fallback');
136136+ // If sync fails, extract what we can from the result.session
137137+ const handle = result.session.handle;
138138+139139+ // Try to get the handle from other properties if undefined
140140+ let fallbackHandle = handle;
141141+ if (!fallbackHandle) {
142142+ // Check if we can extract handle from other properties
143143+ try {
144144+ // If we have additional properties in the session that might contain the handle
145145+ if (result.session.server && result.session.server.login && result.session.server.login.handle) {
146146+ fallbackHandle = result.session.server.login.handle;
147147+ } else if (result.session.displayName && result.session.displayName.includes('@')) {
148148+ // Sometimes displayName has the handle
149149+ fallbackHandle = result.session.displayName.replace('@', '');
150150+ } else {
151151+ // Fallback to 'unknown' if we can't find a handle
152152+ fallbackHandle = 'unknown';
153153+ }
154154+ } catch (e) {
155155+ console.error('Error extracting handle from session:', e);
156156+ fallbackHandle = 'unknown';
157157+ }
158158+ }
159159+160160+ // Log what we're doing
161161+ console.log(`Using client session as fallback with handle: ${fallbackHandle}`);
162162+163163+ // Use client session in our internal format
112164 setSession({
113165 did: result.session.sub,
114114- handle: result.session.handle,
115115- displayName: result.session.handle
166166+ handle: fallbackHandle,
167167+ displayName: result.session.displayName || fallbackHandle
116168 });
117169 }
118170 } catch (syncError) {
119171 console.error('Error syncing initial session:', syncError);
120172173173+ // Extract handle with fallbacks similar to above
174174+ const handle = result.session.handle;
175175+ let fallbackHandle = handle;
176176+177177+ if (!fallbackHandle) {
178178+ try {
179179+ if (result.session.server && result.session.server.login && result.session.server.login.handle) {
180180+ fallbackHandle = result.session.server.login.handle;
181181+ } else if (result.session.displayName && result.session.displayName.includes('@')) {
182182+ fallbackHandle = result.session.displayName.replace('@', '');
183183+ } else {
184184+ fallbackHandle = 'unknown';
185185+ }
186186+ } catch (e) {
187187+ console.error('Error extracting handle from session:', e);
188188+ fallbackHandle = 'unknown';
189189+ }
190190+ }
191191+192192+ console.log(`Using client session after error with handle: ${fallbackHandle}`);
193193+121194 // If sync fails, still use client session in our internal format
122195 setSession({
123196 did: result.session.sub,
124124- handle: result.session.handle,
125125- displayName: result.session.handle
197197+ handle: fallbackHandle,
198198+ displayName: result.session.displayName || fallbackHandle
126199 });
127200 }
128201 } else {
···298371 try {
299372 console.log('Server says not authenticated but we have a client session, trying to sync');
300373374374+ // Extract handle from current session
375375+ let handle = session.handle;
376376+ if (!handle) {
377377+ // If our session doesn't have a handle, try to extract from other properties
378378+ try {
379379+ if (session.displayName && typeof session.displayName === 'string') {
380380+ // Sometimes the handle might be in the displayName
381381+ handle = session.displayName.includes('@') ?
382382+ session.displayName.replace('@', '') :
383383+ session.displayName;
384384+ }
385385+ } catch (e) {
386386+ console.error('Error extracting handle from session:', e);
387387+ }
388388+ }
389389+301390 // Format session data properly
302391 const sessionData = {
303392 did: session.did || session.sub,
304304- handle: session.handle
393393+ handle: handle || 'unknown' // Always provide a handle value
305394 };
395395+396396+ console.log('Syncing with data:', sessionData);
306397307398 // Try to sync one more time
308399 const syncResponse = await fetch('/api/sync-session', {