MCPcopy
hub / github.com/coder/mux / createSessionLocked

Method createSessionLocked

src/node/services/serverAuthService.ts:788–815  ·  view source on GitHub ↗
(opts?: {
    userAgent?: string;
    ipAddress?: string;
  })

Source from the content-addressed store, hash-verified

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,

Callers 1

pollGithubDeviceFlowMethod · 0.95

Calls 9

OkFunction · 0.90
hashSessionTokenFunction · 0.85
normalizeIpAddressFunction · 0.85
buildSessionLabelFunction · 0.85
normalizeOptionalStringFunction · 0.70
pushMethod · 0.65
acquireMethod · 0.45

Tested by

no test coverage detected