Skip to content
Myr

sessions-oauth.ts

This file

Path

apps/platform/src/adapters/sessions-oauth.ts

32 lines · 1.0 KiB · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–32why, one step back
1import { Handle } from "@repo/protocol/ids";
2import { Person } from "@repo/protocol/principal";3import { Clock, Effect, Option, Schema } from "effect";45import { Sessions } from "../sessions.ts";67const GrantProps = Schema.Struct({ handle: Handle });89const decodeProps = Schema.decodeUnknownOption(GrantProps);1011export interface TokenReader {12 readonly unwrapToken: (token: string) => Promise<{13 readonly expiresAt: number;14 readonly grant: { readonly props: unknown };15 } | null>;16}1718export const OAuthSessions = (helpers: TokenReader) =>19 Sessions.of({20 verify: (token) =>21 Effect.gen(function* () {22 const summary = yield* Effect.promise(() => helpers.unwrapToken(token));2324 const now = yield* Clock.currentTimeMillis;2526 return Option.fromNullishOr(summary).pipe(27 Option.filter(({ expiresAt }) => expiresAt * 1000 > now),28 Option.flatMap(({ grant }) => decodeProps(grant.props)),29 Option.map(({ handle }) => Person.make({ handle }))30 );31 }),32 });