session.ts
This file
Path
examples/burrow/packages/auth/src/session.ts
41 lines · 1.1 KiB · TypeScript
Last changed by
Not known.
History of this fileTake 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–41why, one step back1import { API, legacyFetch } from "@burrow/kit";2import type { Transport } from "@burrow/kit";34/** Who a session belongs to, and when it ends. */5export interface Session {6 readonly expiresAt: string;7 readonly user: string;8}910// The session signed in last.11let current: Session | undefined;1213/** Exchanges a sign-in token for a session, and keeps it as the current one. */14export const signIn = async (15 token: string,16 transport?: Transport17): Promise<Session> => {18 const session: Session = JSON.parse(19 await legacyFetch(`${API}/sessions/${encodeURIComponent(token)}`, transport)20 );2122 current = session;2324 return session;25};2627/** The session signed in last, if any. */28export const currentSession = (): Session | undefined => current;2930/** Whether a session's user may act for a team. */31export const isMember = async (32 session: Session,33 team: string,34 transport?: Transport35): Promise<boolean> => {36 const members: readonly string[] = JSON.parse(37 await legacyFetch(`${API}/teams/${encodeURIComponent(team)}`, transport)38 );3940 return members.includes(session.user);41};