feat: support multi-device sign in (#78)
Co-authored-by: Shubham Naik <shub@memgpt.ai>
This commit is contained in:
@@ -66,6 +66,8 @@ export async function pollForToken(
|
||||
deviceCode: string,
|
||||
interval: number = 5,
|
||||
expiresIn: number = 900,
|
||||
deviceId?: string,
|
||||
deviceName?: string,
|
||||
): Promise<TokenResponse> {
|
||||
const startTime = Date.now();
|
||||
const expiresInMs = expiresIn * 1000;
|
||||
@@ -84,6 +86,8 @@ export async function pollForToken(
|
||||
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
||||
client_id: OAUTH_CONFIG.clientId,
|
||||
device_code: deviceCode,
|
||||
...(deviceId && { device_id: deviceId }),
|
||||
...(deviceName && { device_name: deviceName }),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
import { Box, Text, useApp, useInput } from "ink";
|
||||
import { hostname } from "os";
|
||||
import { useState } from "react";
|
||||
import { asciiLogo } from "../cli/components/AsciiArt.ts";
|
||||
import { settingsManager } from "../settings-manager";
|
||||
@@ -62,11 +63,21 @@ export function SetupUI({ onComplete }: SetupUIProps) {
|
||||
console.error("Failed to auto-open browser:", openErr);
|
||||
}
|
||||
|
||||
// Get or generate device ID
|
||||
let deviceId = settingsManager.getSetting("deviceId");
|
||||
if (!deviceId) {
|
||||
deviceId = crypto.randomUUID();
|
||||
settingsManager.updateSettings({ deviceId });
|
||||
}
|
||||
const deviceName = hostname();
|
||||
|
||||
// Start polling in background
|
||||
pollForToken(
|
||||
deviceData.device_code,
|
||||
deviceData.interval,
|
||||
deviceData.expires_in,
|
||||
deviceId,
|
||||
deviceName,
|
||||
)
|
||||
.then((tokens) => {
|
||||
// Save tokens
|
||||
|
||||
@@ -18,6 +18,7 @@ export interface Settings {
|
||||
// OAuth token management
|
||||
refreshToken?: string;
|
||||
tokenExpiresAt?: number; // Unix timestamp in milliseconds
|
||||
deviceId?: string;
|
||||
}
|
||||
|
||||
export interface ProjectSettings {
|
||||
|
||||
Reference in New Issue
Block a user