frontend client for gemstone. decentralised workplace app
2
fork

Configure Feed

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

refactor: fallback on client only in provider

serenity 6c233fc2 b49583fd

+15 -6
+3 -3
src/components/Auth/Login.web.tsx
··· 1 - import { oAuthClient } from "@/lib/utils/atproto/oauth"; 2 1 import { useOAuthSetter, useOAuthValue } from "@/providers/OAuthProvider"; 3 2 import { Agent } from "@atproto/api"; 4 3 import { useState } from "react"; ··· 8 7 const [atprotoHandle, setAtprotoHandle] = useState(""); 9 8 const oAuth = useOAuthValue(); 10 9 const setOAuth = useOAuthSetter(); 11 - const providedOAuthClient = oAuth.client ?? oAuthClient; 10 + const providedOAuthClient = oAuth.client; 11 + 12 12 const handlePress = async () => { 13 13 const session = await providedOAuthClient.signIn(atprotoHandle); 14 14 15 15 const agent = new Agent(session); 16 - 17 16 setOAuth({ 18 17 session, 19 18 agent, 19 + client: providedOAuthClient, 20 20 isLoading: false, 21 21 }); 22 22 };
+10 -1
src/providers/OAuthProvider.tsx
··· 11 11 export interface OAuthContextValue { 12 12 session?: OAuthSession; 13 13 agent?: Agent; 14 - client?: TypedExpoOAuthClientInstance; 14 + client: TypedExpoOAuthClientInstance; 15 15 isLoading: boolean; 16 16 } 17 17 ··· 50 50 export const useOAuthClient = () => { 51 51 const { client } = useOAuthValue(); 52 52 return client; 53 + }; 54 + 55 + export const useOAuthSessionGuaranteed = () => { 56 + const { session } = useOAuthValue(); 57 + if (!session) 58 + throw new Error( 59 + "Tried to access OAuth session before it was created. Ensure that you are calling useOAuthSessionGuaranteed *after* you have a valid OAuth session.", 60 + ); 61 + return session; 53 62 }; 54 63 55 64 export const OAuthProvider = ({ children }: { children: ReactNode }) => {
+2 -2
src/providers/authed/MembershipsProvider.tsx
··· 91 91 "LatticeSessionsProvider must be used within an OAuth provider.", 92 92 ); 93 93 94 - const { session, isLoading, agent, client } = oauth; 95 - const isOAuthReady = !isLoading && !!agent && !!client && !!session; 94 + const { session, isLoading, agent } = oauth; 95 + const isOAuthReady = !isLoading && !!agent && !!session; 96 96 97 97 const membershipsQuery = useQuery({ 98 98 queryKey: ["membership", session?.did],