(opts?: {
userAgent?: string;
ipAddress?: string;
})
| 786 | } |
| 787 | |
| 788 | private async createSessionLocked(opts?: { |
| 789 | userAgent?: string; |
| 790 | ipAddress?: string; |
| 791 | }): Promise<Result<{ sessionId: string; sessionToken: string }, string>> { |
| 792 | const sessionToken = crypto.randomBytes(32).toString("hex"); |
| 793 | const tokenHash = hashSessionToken(sessionToken); |
| 794 | const now = Date.now(); |
| 795 | |
| 796 | const userAgent = normalizeOptionalString(opts?.userAgent); |
| 797 | const ipAddress = normalizeIpAddress(opts?.ipAddress); |
| 798 | |
| 799 | const session: PersistedServerAuthSession = { |
| 800 | id: crypto.randomUUID(), |
| 801 | tokenHash, |
| 802 | createdAtMs: now, |
| 803 | lastUsedAtMs: now, |
| 804 | userAgent, |
| 805 | ipAddress, |
| 806 | label: buildSessionLabel(userAgent), |
| 807 | }; |
| 808 | |
| 809 | await using _lock = await this.sessionsMutex.acquire(); |
| 810 | const data = await this.loadPersistedSessionsLocked(); |
| 811 | data.sessions.push(session); |
| 812 | await this.savePersistedSessionsLocked(data); |
| 813 | |
| 814 | return Ok({ sessionId: session.id, sessionToken }); |
| 815 | } |
| 816 | |
| 817 | private finishGithubDeviceFlow( |
| 818 | flowId: string, |
no test coverage detected