Add stub admin-n authentication for local development.
Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -87,9 +87,9 @@ Each entry is a short note on behaviour and where the code lives. Update this fi
87
87
88
88
## Stub authentication
89
89
90
**Status:** not implemented
91
**Spec:** Until auth.timfalken.com exists, each connection is `admin-<n>` (n = connected clients including this one). Stub accounts are admins.
92
**Code:** —
90
**Status:** full
91
**Spec:** Until auth.timfalken.com exists, each connection is `admin-<n>`. `n` starts at connected-count+1 and skips names already in use so two live sessions cannot share a stub id. Stub accounts are admins.
92
**Code:** `server/src/auth/stub.js`
93
93
94
94
## Characters
95
95
@@ -87,9 +87,9 @@ Each entry is a short note on behaviour and where the code lives. Update this fi87
87
88
## Stub authentication88
## Stub authentication89
89
90
**Status:** not implemented 90
**Status:** full 91
**Spec:** Until auth.timfalken.com exists, each connection is `admin-<n>` (n = connected clients including this one). Stub accounts are admins. 91
**Spec:** Until auth.timfalken.com exists, each connection is `admin-<n>`. `n` starts at connected-count+1 and skips names already in use so two live sessions cannot share a stub id. Stub accounts are admins. 92
**Code:** —92
**Code:** `server/src/auth/stub.js`93
93
94
## Characters94
## Characters95
95
@@ -0,0 +1,38 @@
1
export class StubAuth
2
{
3
constructor ()
4
{
5
this.sessions = new Set();
6
}
7
8
claimIdentity ()
9
{
10
const taken = new Set();
11
for (const session of this.sessions)
12
{
13
const match = /^admin-(\d+)$/.exec(session.authSubject);
14
if (match)
15
{ taken.add(Number(match[1])); }
16
}
17
18
let n = this.sessions.size + 1;
19
while (taken.has(n))
20
{ n += 1; }
21
22
return {
23
authSubject: `admin-${n}`,
24
isAdmin: true,
25
email: null
26
};
27
}
28
29
register (session)
30
{
31
this.sessions.add(session);
32
}
33
34
release (session)
35
{
36
this.sessions.delete(session);
37
}
38
}
@@ -0,0 +1,38 @@1
export class StubAuth2
{3
constructor ()4
{5
this.sessions = new Set();6
}7
8
claimIdentity ()9
{10
const taken = new Set();11
for (const session of this.sessions)12
{13
const match = /^admin-(\d+)$/.exec(session.authSubject);14
if (match)15
{ taken.add(Number(match[1])); }16
}17
18
let n = this.sessions.size + 1;19
while (taken.has(n))20
{ n += 1; }21
22
return {23
authSubject: `admin-${n}`,24
isAdmin: true,25
email: null26
};27
}28
29
register (session)30
{31
this.sessions.add(session);32
}33
34
release (session)35
{36
this.sessions.delete(session);37
}38
}