conditional imports

This commit is contained in:
Hailey
2025-07-18 00:34:38 -07:00
parent 796d989781
commit decd501a73
6 changed files with 38 additions and 26 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ import {useNavigation} from '@react-navigation/native'
import {type NavigationProp} from '#/lib/routes/types'
import {useSessionApi} from '#/state/session'
import {getWebOAuthClient} from '#/state/session/oauth'
import {getWebOAuthClient} from '#/state/session/oauth-web-client'
export function AuthCallback() {
const {loginOauth} = useSessionApi()
+2 -1
View File
@@ -22,7 +22,8 @@ import {logger} from '#/logger'
import {isWeb} from '#/platform/detection'
import {useSetHasCheckedForStarterPack} from '#/state/preferences/used-starter-packs'
import {useSessionApi} from '#/state/session'
import {getNativeOAuthClient, getWebOAuthClient} from '#/state/session/oauth'
import {getNativeOAuthClient} from '#/state/session/oauth-native-client'
import {getWebOAuthClient} from '#/state/session/oauth-web-client'
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
+1 -1
View File
@@ -26,7 +26,7 @@ import {
configureModerationForAccount,
configureModerationForGuest,
} from './moderation'
import {BSKY_OAUTH_CLIENT} from './oauth'
import {BSKY_OAUTH_CLIENT} from './oauth-web-client'
import {type SessionAccount} from './types'
import {isSessionExpired, isSignupQueued} from './util'
+25
View File
@@ -0,0 +1,25 @@
import {ExpoOAuthClient} from 'expo-atproto-auth'
import {BSKY_OAUTH_CLIENT} from './oauth-web-client'
export function createNativeOAuthClient() {
return new ExpoOAuthClient({
clientMetadata: {
client_id: 'https://bsky.hailey.at/oauth-client-metadata.native.json',
client_name: 'Bluesky Native App (Hailey Demo)',
client_uri: 'https://bsky.hailey.at',
redirect_uris: ['at.hailey.bsky:/auth/native/callback'],
scope: 'atproto transition:generic',
token_endpoint_auth_method: 'none',
response_types: ['code'],
grant_types: ['authorization_code', 'refresh_token'],
application_type: 'native',
dpop_bound_access_tokens: true,
},
handleResolver: 'https://bsky.social',
})
}
export function getNativeOAuthClient() {
return BSKY_OAUTH_CLIENT as ExpoOAuthClient
}
@@ -0,0 +1,7 @@
export function createNativeOAuthClient() {
throw new Error('createNativeOAuthClient called on web')
}
export function getNativeOAuthClient() {
throw new Error('getNativeOAuthClient called on web')
}
@@ -1,8 +1,9 @@
import {Platform} from 'react-native'
import {ExpoOAuthClient} from 'expo-atproto-auth'
import {type OAuthClient} from '@atproto/oauth-client'
import {BrowserOAuthClient} from '@atproto/oauth-client-browser'
import {createNativeOAuthClient} from './oauth-native-client'
export const BSKY_OAUTH_CLIENT: OAuthClient =
Platform.OS === 'web' ? createWebOAuthClient() : createNativeOAuthClient()
@@ -24,28 +25,6 @@ export function createWebOAuthClient() {
})
}
export function createNativeOAuthClient() {
return new ExpoOAuthClient({
clientMetadata: {
client_id: 'https://bsky.hailey.at/oauth-client-metadata.native.json',
client_name: 'Bluesky Native App (Hailey Demo)',
client_uri: 'https://bsky.hailey.at',
redirect_uris: ['at.hailey.bsky:/auth/native/callback'],
scope: 'atproto transition:generic',
token_endpoint_auth_method: 'none',
response_types: ['code'],
grant_types: ['authorization_code', 'refresh_token'],
application_type: 'native',
dpop_bound_access_tokens: true,
},
handleResolver: 'https://bsky.social',
})
}
export function getNativeOAuthClient() {
return BSKY_OAUTH_CLIENT as ExpoOAuthClient
}
export function getWebOAuthClient() {
return BSKY_OAUTH_CLIENT as BrowserOAuthClient
}