feat(mobile): connect Android and IDE to browser account login

This commit is contained in:
yilsem committed 2026-09-08 21:10:49 +03:00
1 parent b66daed07a
commit c1929957a2
8 files changed
+109 -8

No files matched your search

+33 -1
View File
@@ -30,8 +30,40 @@ function event(frame) {
}
}
}
action('login-start', async () => {
if (credentials.accountToken || connection) throw new Error('Kayıtlı hesabınız var; önce mevcut cihaz erişimini iptal edin.')
const result = await new AccountClient({}).call('/v1/aiturk/mobile-auth/start', {})
if (!/^https:\/\/turkservis\.online\/account\/aiturk\/mobile-login\/[0-9a-f-]{36}$/.test(result.verificationUri)) throw new Error('Geçersiz giriş sayfası.')
credentials.pendingLogin = result; await saveCredentials()
$('login-code').textContent = `Yalnız kendi hesabınızda bu kodu onaylayın: ${result.userCode}`
$('login-link').href = result.verificationUri; $('login-link').hidden = false
if (native()) await native().openLogin({ url: result.verificationUri })
status('Tarayıcıda giriş yaptıktan sonra buraya dönüp girişi kontrol edin.')
})
action('login-check', async () => {
if (!credentials.pendingLogin) throw new Error('Önce giriş başlatın.')
const result = await new AccountClient({ accountToken: credentials.pendingLogin.deviceCode }).call('/v1/aiturk/mobile-auth/poll', {})
if (result.state !== 'approved') { status('Tarayıcıdaki kod onayı bekleniyor.'); return }
credentials.accountToken = result.accountToken; delete credentials.pendingLogin; await saveCredentials()
account = new AccountClient(credentials); $('login-code').textContent = 'Hesaba giriş yapıldı.'; $('login-link').hidden = true
status('Hesap bağlı. Şimdi telefonun eşleştirme kodunu oluşturun.')
})
action('logout', async () => {
const token = credentials.accountToken || credentials.pendingLogin?.deviceCode
// Revoke the app-specific credential before dropping the local copy. A
// network failure leaves it available for an explicit retry.
if (token?.startsWith('tsml_')) await new AccountClient({ accountToken: token }).call('/v1/aiturk/mobile-auth/logout', {})
connectionEpoch++; stopVoice(); connection?.close(); connection = null; selected = null; account = null
credentials = {}; pendingTask = null; await saveCredentials()
$('work').hidden = true; $('login-link').hidden = true; $('login-code').textContent = ''; $('pair-code').textContent = ''
status('Bu uygulamanın oturumu kapatıldı. IDE’de başlamış iş kendi çalışma kurallarıyla devam edebilir.')
})
action('pair', async () => {
credentials = { accountToken: $('account-token').value.trim() }; $('account-token').value = ''
if (credentials.deviceId) throw new Error('Bu telefon zaten eşleşme başlatmış. Bilgisayarları bulun veya mevcut erişimi iptal edin.')
const manual = $('account-token').value.trim(); $('account-token').value = ''
if (manual && credentials.accountToken && manual !== credentials.accountToken) throw new Error('Kayıtlı hesap sessizce değiştirilemez.')
if (manual) credentials.accountToken = manual
if (!credentials.accountToken) throw new Error('Önce AITURK hesabınıza giriş yapın.')
account = new AccountClient(credentials)
const result = await account.call('/v1/aiturk/pairings', { display_name: $('device-name').value.trim(), platform: 'android' })
Object.assign(credentials, { deviceId: result.device_id, deviceToken: result.device_token, pairingId: result.pairing_id })