···6 BrowserOAuthClient,
7 OAuthSession,
8} from "@atproto/oauth-client-browser";
9+import { useRouter } from "@tanstack/react-router";
10import {
11 createContext,
12 ReactNode,
···22 callbackHandler: (arg0: URLSearchParams) => void;
23 handle: string | null;
24 setHandle: (arg0: string) => void;
25+ signOut: () => void;
26} | null>(null);
2728export const OAuthProvider = ({ children }: { children: ReactNode }) => {
···50 [client],
51 );
5253+ // when we move this to a package, remove this.
54+ const router = useRouter();
55+56+ const signOut = () => {
57+ if (!session)
58+ throw new Error(
59+ "No OAuth session found. You should be careful about the ordering of your calls. Ensure that the client and the session is loaded before attempting to call `signOut` on the OAuth provider.",
60+ );
61+62+ session.signOut();
63+ setSession(null);
64+ };
65+66+ // When we release the package, we need to remove this and replace it with a prop that takes in any effectful function and runs it here.
67+ // For now, we just perform the effect.
68+69+ useEffect(() => {
70+ router.invalidate();
71+ }, [session]);
72+73 useEffect(() => {
74 const oAuthClient = new BrowserOAuthClient({
75 //@ts-expect-error fuck it we ball
···110 callbackHandler,
111 handle,
112 setHandle,
113+ signOut,
114 };
115116 return <OAuthContext value={contextValue}>{children}</OAuthContext>;