Skip to content

Commit 8be7fb8

Browse files
committed
feat: tauri-plugin-http for GitHub Device Flow — bypasses CORS on iOS
1 parent 7b7276e commit 8be7fb8

8 files changed

Lines changed: 514 additions & 9 deletions

File tree

lib/github-api.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,18 @@ export interface DeviceCodeResponse {
9494
interval: number
9595
}
9696

97+
/** Use Tauri HTTP plugin (bypasses CORS) when available, otherwise browser fetch */
98+
async function nativeFetch(url: string, init: RequestInit): Promise<Response> {
99+
try {
100+
const { fetch: tauriFetch } = await import('@tauri-apps/plugin-http')
101+
return await tauriFetch(url, init)
102+
} catch {
103+
return fetch(url, init)
104+
}
105+
}
106+
97107
export async function startDeviceFlow(): Promise<DeviceCodeResponse> {
98-
const res = await fetch('https://github.com/login/device/code', {
108+
const res = await nativeFetch('https://github.com/login/device/code', {
99109
method: 'POST',
100110
headers: {
101111
Accept: 'application/json',
@@ -119,7 +129,7 @@ export async function pollDeviceFlow(
119129
for (let i = 0; i < 60; i++) {
120130
if (signal?.aborted) throw new Error('Cancelled')
121131
await delay(interval * 1000)
122-
const res = await fetch('https://github.com/login/oauth/access_token', {
132+
const res = await nativeFetch('https://github.com/login/oauth/access_token', {
123133
method: 'POST',
124134
headers: {
125135
Accept: 'application/json',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@tauri-apps/api": "^2.10.1",
4949
"@tauri-apps/plugin-clipboard-manager": "^2.3.2",
5050
"@tauri-apps/plugin-dialog": "^2.6.0",
51+
"@tauri-apps/plugin-http": "^2.5.7",
5152
"@tauri-apps/plugin-shell": "^2.3.5",
5253
"@tauri-apps/plugin-window-state": "^2.4.1",
5354
"@types/dompurify": "^3.2.0",

pnpm-lock.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)