frontend client for gemstone. decentralised workplace app

feat: sessions provider

serenity c8d17a1d b01bfe5f

Changed files
+48 -4
src
app
(protected)
lib
types
utils
atproto
providers
queries
+4 -1
src/app/(protected)/_layout.tsx
···
import { SessionGate } from "@/components/Auth/SessionGate";
+
import { AuthedProviders } from "@/providers/authed";
import { Stack } from "expo-router";
export default function ProtectedLayout() {
return (
<SessionGate>
-
<Stack />
+
<AuthedProviders>
+
<Stack />
+
</AuthedProviders>
</SessionGate>
);
}
+12
src/lib/types/handshake.ts
···
+
import { atUriSchema, didSchema } from "@/lib/types/atproto";
+
import { z } from "zod";
+
+
export const latticeSessionInfoSchema = z.object({
+
id: z.string(),
+
token: z.string(),
+
fingerprint: z.string(),
+
allowedChannels: z.array(atUriSchema),
+
clientDid: didSchema,
+
latticeDid: didSchema,
+
});
+
export type LatticeSessionInfo = z.infer<typeof latticeSessionInfoSchema>;
+2 -1
src/lib/utils/atproto/client.ts
···
import { Client, simpleFetchHandler } from "@atcute/client";
import type {} from "@atcute/bluesky";
+
import type {} from "@atcute/atproto";
const handler = simpleFetchHandler({ service: "https://public.api.bsky.app" });
-
export const atprotoClient = new Client({ handler });
+
export const bskyClient = new Client({ handler });
+22
src/providers/authed/LatticeSessionsProvider.tsx
···
+
import type { Did } from "@/lib/types/atproto";
+
import type { LatticeSessionInfo } from "@/lib/types/handshake";
+
import type { ReactNode } from "react";
+
import { createContext } from "react";
+
+
type LatticeSessions = Map<Did, LatticeSessionInfo>;
+
+
interface LatticeSessionContextValue {
+
sessions: LatticeSessions;
+
}
+
+
const LatticeSessionsContext = createContext<LatticeSessionContextValue | null>(
+
null,
+
);
+
+
export const LatticeSessionsProvider = ({
+
children,
+
}: {
+
children: ReactNode;
+
}) => {
+
return <LatticeSessionsContext>{children}</LatticeSessionsContext>;
+
};
+6
src/providers/authed/index.tsx
···
+
import { LatticeSessionsProvider } from "@/providers/authed/LatticeSessionsProvider";
+
import type { ReactNode } from "react";
+
+
export const AuthedProviders = ({ children }: { children: ReactNode }) => {
+
return <LatticeSessionsProvider>{children}</LatticeSessionsProvider>;
+
};
+2 -2
src/queries/get-profile.ts
···
import type { DidPlc, DidWeb } from "@/lib/types/atproto";
-
import { atprotoClient } from "@/lib/utils/atproto/client";
+
import { bskyClient } from "@/lib/utils/atproto/client";
export const getBskyProfile = async (did: DidPlc | DidWeb) => {
-
const { ok, data } = await atprotoClient.get("app.bsky.actor.getProfile", {
+
const { ok, data } = await bskyClient.get("app.bsky.actor.getProfile", {
params: {
actor: did,
},