BlueGit

timfa questward

Files

questward / server / src / auth / stub.js

stub.js

stub.js 554 B Download Raw
1export 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}