Your music, beautifully tracked. All yours. (coming soon) teal.fm
teal-fm atproto

add external pds support :sob:

+40 -2
+40 -2
apps/amethyst/stores/authenticationSlice.tsx
··· 6 6 import * as Lexicons from "@teal/lexicons/src/lexicons"; 7 7 import { resolveFromIdentity } from "@/lib/atp/pid"; 8 8 9 + export interface AllProfileViews { 10 + bsky: null | ProfileViewDetailed; 11 + // todo: teal profile view 12 + } 13 + 9 14 export interface AuthenticationSlice { 10 15 auth: AquareumOAuthClient; 11 16 status: "start" | "loggedIn" | "loggedOut"; ··· 13 18 oauthSession: null | OAuthSession; 14 19 pdsAgent: null | Agent; 15 20 isAgentReady: boolean; 16 - profiles: { [key: string]: ProfileViewDetailed }; 21 + profiles: { [key: string]: AllProfileViews }; 17 22 client: null | AquareumOAuthClient; 18 23 login: { 19 24 loading: boolean; ··· 28 33 oauthCallback: (state: URLSearchParams) => Promise<void>; 29 34 restorePdsAgent: () => void; 30 35 logOut: () => void; 36 + populateLoggedInProfile: () => Promise<void>; 31 37 } 32 38 33 39 export const createAuthenticationSlice: StateCreator<AuthenticationSlice> = ( ··· 96 102 pdsAgent: addDocs(agent), 97 103 isAgentReady: true, 98 104 }); 105 + get().populateLoggedInProfile(); 99 106 } catch (error: any) { 100 107 console.error("OAuth callback failed:", error); 101 108 set({ ··· 131 138 isAgentReady: true, 132 139 status: "loggedIn", 133 140 }); 141 + get().populateLoggedInProfile(); 134 142 console.log("Restored agent"); 135 143 } catch (error) { 136 144 console.error("Failed to restore agent:", error); ··· 139 147 }, 140 148 logOut: () => { 141 149 console.log("Logging out"); 150 + let profiles = { ...get().profiles }; 151 + // TODO: something better than 'delete' 152 + delete profiles[get().pdsAgent?.did ?? ""]; 142 153 set({ 143 154 status: "loggedOut", 144 155 oauthSession: null, 145 156 oauthState: null, 146 - profiles: {}, 157 + profiles, 147 158 pdsAgent: null, 148 159 client: null, 160 + pds: null, 149 161 }); 162 + }, 163 + populateLoggedInProfile: async () => { 164 + console.log("Populating logged in profile"); 165 + const agent = get().pdsAgent; 166 + if (!agent) { 167 + throw new Error("No agent"); 168 + } 169 + if (!agent.did) { 170 + throw new Error("No agent did! This is bad!"); 171 + } 172 + try { 173 + let bskyProfile = await agent 174 + .getProfile({ actor: agent.did }) 175 + .then((profile) => { 176 + console.log(profile); 177 + return profile.data || null; 178 + }); 179 + 180 + set({ 181 + profiles: { 182 + [agent.did]: { bsky: bskyProfile }, 183 + }, 184 + }); 185 + } catch (error) { 186 + console.error("Failed to get profile:", error); 187 + } 150 188 }, 151 189 }; 152 190 };