accounts.ts
This file
Path
apps/platform/src/auth/accounts.ts
75 lines · 2.2 KiB · TypeScript
Last changed by
Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c
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
line 1why, one step back1import type { Handle } from "@repo/protocol/ids";Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c
line 2why, one step back2import { Context, Data, Schema } from "effect";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 3–6why, one step back3import type { Effect, Option } from "effect";45import type { PasswordHash } from "./password.ts";6Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c
lines 7–36why, one step back7// Enough to catch a typo; the mailed code is what proves the address.8export const Email = Schema.String.check(9 Schema.isMaxLength(254),10 Schema.isPattern(/^[^\s@]+@[^\s@]+\.[^\s@]+$/u)11).pipe(Schema.brand("Email"));1213export type Email = typeof Email.Type;1415// The rule two spellings of one address are compared by.16export const emailKey = (email: Email) => email.toLowerCase();1718const graphemes = new Intl.Segmenter("en", { granularity: "grapheme" });1920export const DisplayName = Schema.String.check(21 Schema.makeFilter((name) => {22 const { length } = [...graphemes.segment(name)];2324 return name === name.trim() &&25 length >= 1 &&26 length <= 64 &&27 !/\p{Cc}/u.test(name)28 ? true29 : "1 to 64 characters, with no space at either end";30 })31).pipe(Schema.brand("DisplayName"));3233export type DisplayName = typeof DisplayName.Type;3435// Sign-up always sets `email` and `displayName`; only accounts made before36// either existed lack them.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
line 37why, one step back37export interface Account {Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c
lines 38–39why, one step back38 readonly displayName?: DisplayName;39 readonly email?: Email;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 40–47why, one step back40 readonly handle: Handle;41 readonly hash: PasswordHash;42}4344export class HandleTaken extends Data.TaggedError("HandleTaken")<{45 readonly handle: Handle;46}> {}47Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c
lines 48–51why, one step back48export class EmailTaken extends Data.TaggedError("EmailTaken")<{49 readonly email: Email;50}> {}51Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
line 52why, one step back52// The rule `sameHandle` compares by, so a racing second sign-up fails on the key.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 53–58why, one step back53export const handleKey = (handle: Handle) => handle.toLowerCase();5455export class Accounts extends Context.Service<56 Accounts,57 {58 readonly create: (Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c
lines 59–60why, one step back59 account: Account60 ) => Effect.Effect<void, HandleTaken | EmailTaken>;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
line 61why, one step back61 readonly find: (handle: Handle) => Effect.Effect<Option.Option<Account>>;Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c
lines 62–69why, one step back62 readonly findByEmail: (63 email: Email64 ) => Effect.Effect<Option.Option<Account>>;65 // Only once its person proved the address.66 readonly setEmail: (67 handle: Handle,68 email: Email69 ) => Effect.Effect<void, EmailTaken>;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 70–75why, one step back70 readonly setPasswordHash: (71 handle: Handle,72 hash: PasswordHash73 ) => Effect.Effect<void>;74 }75>()("platform/Accounts") {}