diff --git a/oauth/src/App.tsx b/oauth/src/App.tsx index b9b9b4b..7872464 100644 --- a/oauth/src/App.tsx +++ b/oauth/src/App.tsx @@ -431,17 +431,24 @@ function App() { if (user.did && user.did.includes('-placeholder')) { // Resolving placeholder DID try { - const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(user.handle)}`); - if (profileResponse.ok) { - const profileData = await profileResponse.json(); - if (profileData.did) { - // Resolved DID - return { - ...user, - did: profileData.did - }; + let profileData; + if (agent) { + const profileResponse = await agent.getProfile({ actor: user.handle }); + profileData = profileResponse.data; + } else { + // フォールバック:public API + const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(user.handle)}`); + if (profileResponse.ok) { + profileData = await profileResponse.json(); } } + if (profileData.did) { + // Resolved DID + return { + ...user, + did: profileData.did + }; + } } catch (err) { // Failed to resolve DID } @@ -580,23 +587,29 @@ function App() { sortedComments.map(async (record) => { if (!record.value.author?.avatar && record.value.author?.handle) { try { - // Public API でプロフィール取得 - const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(record.value.author.handle)}`); - - if (profileResponse.ok) { - const profileData = await profileResponse.json(); - return { - ...record, - value: { - ...record.value, - author: { - ...record.value.author, - avatar: profileData.avatar, - displayName: profileData.displayName || record.value.author.handle, - } - } - }; + let profileData; + if (agent) { + // 認証されたAPIでプロフィール取得 + const profileResponse = await agent.getProfile({ actor: record.value.author.handle }); + profileData = profileResponse.data; + } else { + // フォールバック:public API + const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(record.value.author.handle)}`); + if (profileResponse.ok) { + profileData = await profileResponse.json(); + } } + return { + ...record, + value: { + ...record.value, + author: { + ...record.value.author, + avatar: profileData.avatar, + displayName: profileData.displayName || record.value.author.handle, + } + } + }; } catch (err) { // Ignore enhancement errors } @@ -796,14 +809,21 @@ function App() { let resolvedDid = `did:plc:${handle.replace(/\./g, '-')}-placeholder`; // フォールバック try { - // Public APIでプロフィールを取得してDIDを解決 - const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handle)}`); - if (profileResponse.ok) { - const profileData = await profileResponse.json(); - if (profileData.did) { - resolvedDid = profileData.did; + let profileData; + if (agent) { + // 認証されたAPIでプロフィールを取得してDIDを解決 + const profileResponse = await agent.getProfile({ actor: handle }); + profileData = profileResponse.data; + } else { + // フォールバック:public API + const profileResponse = await fetch(`${appConfig.bskyPublicApi}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(handle)}`); + if (profileResponse.ok) { + profileData = await profileResponse.json(); } } + if (profileData.did) { + resolvedDid = profileData.did; + } } catch (err) { } @@ -1534,27 +1554,6 @@ function App() { )} - {/* User Section - moved from above */} - {user && !appConfig.rkey && ( -
@{user.handle}
-{user.did}
-