* Fetches the mini profile for the authenticated user, including their avatar if available. * This is used to populate the session with basic user info after authentication. * @param authSession The OAuth session containing the user's DID and token info * @returns An object containing the user's
(authSession: OAuthSession)
| 225 | * @returns An object containing the user's DID, handle, PDS, and avatar URL (if available) |
| 226 | */ |
| 227 | async function getMiniProfile(authSession: OAuthSession) { |
| 228 | const response = await slingshotClient.xrpcSafe(blue.microcosm.identity.resolveMiniDoc, { |
| 229 | headers: { 'User-Agent': 'npmx' }, |
| 230 | params: { identifier: authSession.did }, |
| 231 | }) |
| 232 | |
| 233 | if (response.success) { |
| 234 | const miniDoc = response.body |
| 235 | |
| 236 | let avatar: string | undefined = await getAvatar(authSession.did, miniDoc.pds) |
| 237 | |
| 238 | return { |
| 239 | ...miniDoc, |
| 240 | avatar, |
| 241 | } |
| 242 | } else { |
| 243 | //If slingshot fails we still want to set some key info we need. |
| 244 | const pdsBase = (await authSession.getTokenInfo()).aud |
| 245 | let avatar: string | undefined = await getAvatar(authSession.did, pdsBase) |
| 246 | return { |
| 247 | did: authSession.did, |
| 248 | handle: 'Not available', |
| 249 | pds: pdsBase, |
| 250 | avatar, |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Fetch the user's profile record to get their avatar blob reference |
no test coverage detected