tangled
alpha
login
or
join now
teal.fm
/
teal
110
fork
atom
Your music, beautifully tracked. All yours. (coming soon)
teal.fm
teal-fm
atproto
110
fork
atom
overview
issues
pulls
pipelines
add external pds support :sob:
Natalie B.
1 year ago
0c6aab1f
2055850a
+40
-2
1 changed file
expand all
collapse all
unified
split
apps
amethyst
stores
authenticationSlice.tsx
+40
-2
apps/amethyst/stores/authenticationSlice.tsx
···
6
import * as Lexicons from "@teal/lexicons/src/lexicons";
7
import { resolveFromIdentity } from "@/lib/atp/pid";
8
0
0
0
0
0
9
export interface AuthenticationSlice {
10
auth: AquareumOAuthClient;
11
status: "start" | "loggedIn" | "loggedOut";
···
13
oauthSession: null | OAuthSession;
14
pdsAgent: null | Agent;
15
isAgentReady: boolean;
16
-
profiles: { [key: string]: ProfileViewDetailed };
17
client: null | AquareumOAuthClient;
18
login: {
19
loading: boolean;
···
28
oauthCallback: (state: URLSearchParams) => Promise<void>;
29
restorePdsAgent: () => void;
30
logOut: () => void;
0
31
}
32
33
export const createAuthenticationSlice: StateCreator<AuthenticationSlice> = (
···
96
pdsAgent: addDocs(agent),
97
isAgentReady: true,
98
});
0
99
} catch (error: any) {
100
console.error("OAuth callback failed:", error);
101
set({
···
131
isAgentReady: true,
132
status: "loggedIn",
133
});
0
134
console.log("Restored agent");
135
} catch (error) {
136
console.error("Failed to restore agent:", error);
···
139
},
140
logOut: () => {
141
console.log("Logging out");
0
0
0
142
set({
143
status: "loggedOut",
144
oauthSession: null,
145
oauthState: null,
146
-
profiles: {},
147
pdsAgent: null,
148
client: null,
0
149
});
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
150
},
151
};
152
};
···
6
import * as Lexicons from "@teal/lexicons/src/lexicons";
7
import { resolveFromIdentity } from "@/lib/atp/pid";
8
9
+
export interface AllProfileViews {
10
+
bsky: null | ProfileViewDetailed;
11
+
// todo: teal profile view
12
+
}
13
+
14
export interface AuthenticationSlice {
15
auth: AquareumOAuthClient;
16
status: "start" | "loggedIn" | "loggedOut";
···
18
oauthSession: null | OAuthSession;
19
pdsAgent: null | Agent;
20
isAgentReady: boolean;
21
+
profiles: { [key: string]: AllProfileViews };
22
client: null | AquareumOAuthClient;
23
login: {
24
loading: boolean;
···
33
oauthCallback: (state: URLSearchParams) => Promise<void>;
34
restorePdsAgent: () => void;
35
logOut: () => void;
36
+
populateLoggedInProfile: () => Promise<void>;
37
}
38
39
export const createAuthenticationSlice: StateCreator<AuthenticationSlice> = (
···
102
pdsAgent: addDocs(agent),
103
isAgentReady: true,
104
});
105
+
get().populateLoggedInProfile();
106
} catch (error: any) {
107
console.error("OAuth callback failed:", error);
108
set({
···
138
isAgentReady: true,
139
status: "loggedIn",
140
});
141
+
get().populateLoggedInProfile();
142
console.log("Restored agent");
143
} catch (error) {
144
console.error("Failed to restore agent:", error);
···
147
},
148
logOut: () => {
149
console.log("Logging out");
150
+
let profiles = { ...get().profiles };
151
+
// TODO: something better than 'delete'
152
+
delete profiles[get().pdsAgent?.did ?? ""];
153
set({
154
status: "loggedOut",
155
oauthSession: null,
156
oauthState: null,
157
+
profiles,
158
pdsAgent: null,
159
client: null,
160
+
pds: null,
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
+
}
188
},
189
};
190
};