who.ts
This file
Path
apps/web/src/features/auth/who.ts
15 lines · 619 bytes · TypeScript
Last changed by
Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72
History of this fileTake it
12345678910111213141516import { Handle } from "@repo/protocol/ids";import { Effect, Option, Schema } from "effect";import { FetchHttpClient, HttpClient, HttpClientResponse } from "effect/http";import { Atom } from "effect/reactivity";
const Who = Schema.Struct({ handle: Schema.optionalKey(Handle) });
export const whoAtom = Atom.make( HttpClient.get("/auth/whoami").pipe( Effect.flatMap(HttpClientResponse.schemaBodyJson(Who)), Effect.map(({ handle }) => Option.fromUndefinedOr(handle)), Effect.orElseSucceed(() => Option.none<Handle>()), Effect.provide(FetchHttpClient.layer) )).pipe(Atom.withServerValueInitial);