Live video on the AT Protocol
79
fork

Configure Feed

Select the types of activity you want to include in your feed.

app: clear oauth session stuff on rejection (#227)

* app: clear oauth session stuff on rejection

* app: handle changeURL action for anonPDS

authored by

Eli Mallon and committed by
GitHub
46509857 e622d204

+44 -10
+40 -8
js/app/features/bluesky/blueskySlice.tsx
··· 15 15 MessageViewHydrated, 16 16 PlayersState, 17 17 } from "features/player/playerSlice"; 18 - import { StreamplaceState } from "features/streamplace/streamplaceSlice"; 18 + import { 19 + StreamplaceState, 20 + setURL, 21 + } from "features/streamplace/streamplaceSlice"; 19 22 import { 20 23 PlaceStreamChatMessage, 21 24 PlaceStreamChatProfile, ··· 39 42 oauthState: null, 40 43 oauthSession: null, 41 44 pdsAgent: null, 45 + anonPDSAgent: null, 42 46 profiles: {}, 43 47 profileCache: {}, 44 48 client: null, ··· 108 112 storedKey: action.payload.storedKey, 109 113 }; 110 114 }); 115 + builder.addCase(setURL, (state, action) => { 116 + return { 117 + ...state, 118 + anonPDSAgent: new StreamplaceAgent(action.payload) as any, 119 + }; 120 + }); 121 + builder.addDefaultCase((state, action) => { 122 + const err = (action as any).error as { message: string }; 123 + if ( 124 + typeof err === "object" && 125 + typeof err?.message === "string" && 126 + err.message.includes("oauth session revoked") 127 + ) { 128 + Storage.removeItem("did").catch((e) => { 129 + console.error("Error removing did", e); 130 + }); 131 + Storage.removeItem(STORED_KEY_KEY).catch((e) => { 132 + console.error("Error removing stored key", e); 133 + }); 134 + const u = new URL(document.location.href); 135 + return { 136 + ...state, 137 + oauthSession: null, 138 + status: "loggedOut", 139 + pdsAgent: null, 140 + }; 141 + } 142 + return state; 143 + }); 111 144 }, 112 145 reducers: (create) => ({ 113 146 loadOAuthClient: create.asyncThunk( 114 147 async (_, { getState }) => { 115 148 const { streamplace } = getState() as { streamplace: StreamplaceState }; 116 149 const client = await createOAuthClient(streamplace.url); 150 + const anonPDSAgent = new StreamplaceAgent(streamplace.url); 117 151 let initResult = await client.init(); 118 - return { client, initResult }; 152 + return { client, initResult, anonPDSAgent }; 119 153 }, 120 154 { 121 155 pending: (state) => { 122 156 // state.status = "loading"; 123 157 }, 124 158 fulfilled: (state, action) => { 125 - const { client, initResult } = action.payload; 159 + const { client, initResult, anonPDSAgent } = action.payload; 126 160 console.log("loadOAuthClient fulfilled", action.payload); 127 - // sometimes the codes don't get removed from the url properly? so we do so here. 128 - // const u = new URL(document.location.href); 129 - // u.search = ""; 130 - // window.history.replaceState(null, "", u.toString()); 131 161 if (initResult && "session" in initResult) { 132 162 return { 133 163 ...state, 134 164 client: client, 135 165 oauthSession: initResult.session as any, 136 - pdsAgent: new StreamplaceAgent(initResult.session), 166 + pdsAgent: new StreamplaceAgent(initResult.session) as any, // idk why this is needed 167 + anonPDSAgent: anonPDSAgent, 137 168 }; 138 169 } 139 170 return { 140 171 ...state, 141 172 status: "loggedOut", 142 173 client: client, 174 + anonPDSAgent: anonPDSAgent, 143 175 }; 144 176 }, 145 177 rejected: (state, { error }) => {
+1
js/app/features/bluesky/blueskyTypes.tsx
··· 16 16 oauthState: null | string; 17 17 oauthSession: null | OAuthSession; 18 18 pdsAgent: null | StreamplaceAgent; 19 + anonPDSAgent: null | StreamplaceAgent; 19 20 profiles: { [key: string]: ProfileViewDetailed }; 20 21 // for e.g. others' avatars 21 22 profileCache: { [key: string]: ProfileViewDetailed };
js/app/features/streamplace/streamplaceActions.tsx

This is a binary file and will not be displayed.

+3 -2
js/app/features/streamplace/streamplaceSlice.tsx
··· 133 133 ), 134 134 135 135 setURL: create.reducer((state, action: { payload: string }) => { 136 + console.log("setURL", action); 136 137 Storage.setItem(URL_KEY, action.payload).catch((err) => { 137 138 console.error("setURL error", err); 138 139 }); ··· 212 213 bluesky: BlueskyState; 213 214 }; 214 215 215 - let agent = bluesky.pdsAgent; 216 + let agent = bluesky.anonPDSAgent; 216 217 217 218 if (!agent) { 218 - agent = new StreamplaceAgent(streamplace.url); 219 + throw new Error("no anonPDSAgent"); 219 220 } 220 221 221 222 let users = await agent.place.stream.live.getLiveUsers();