Skip to content
Myr

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 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

line 1why, one step back
1import 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 back
2import { 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 back
3import type { Effect, Option } from "effect";
45import type { PasswordHash } from "./password.ts";6

Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c

lines 7–36why, one step back
7// 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 back
37export interface Account {

Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c

lines 38–39why, one step back
38 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 back
40 readonly handle: Handle;
41 readonly hash: PasswordHash;42}4344export class HandleTaken extends Data.TaggedError("HandleTaken")<{45 readonly handle: Handle;46}> {}47

Sign people in by a proven email, with a display name, and Google's emailoscabrielbefore adoption125964c

lines 48–51why, one step back
48export class EmailTaken extends Data.TaggedError("EmailTaken")<{
49 readonly email: Email;50}> {}51

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

line 52why, one step back
52// 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 back
53export 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 back
59 account: Account
60 ) => 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 back
61 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 back
62 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 back
70 readonly setPasswordHash: (
71 handle: Handle,72 hash: PasswordHash73 ) => Effect.Effect<void>;74 }75>()("platform/Accounts") {}