diff --git a/src/screens/Login/AuthCallback.tsx b/src/screens/Login/AuthCallback.tsx index 90682ac54c..bd9c363f02 100644 --- a/src/screens/Login/AuthCallback.tsx +++ b/src/screens/Login/AuthCallback.tsx @@ -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() diff --git a/src/screens/Login/LoginForm.tsx b/src/screens/Login/LoginForm.tsx index 342c115a98..12e8f7f3fc 100644 --- a/src/screens/Login/LoginForm.tsx +++ b/src/screens/Login/LoginForm.tsx @@ -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' diff --git a/src/state/session/agent.ts b/src/state/session/agent.ts index 3898e54db2..0e04fe5c9d 100644 --- a/src/state/session/agent.ts +++ b/src/state/session/agent.ts @@ -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' diff --git a/src/state/session/oauth-native-client.ts b/src/state/session/oauth-native-client.ts new file mode 100644 index 0000000000..bee15ea260 --- /dev/null +++ b/src/state/session/oauth-native-client.ts @@ -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 +} diff --git a/src/state/session/oauth-native-client.web.ts b/src/state/session/oauth-native-client.web.ts new file mode 100644 index 0000000000..0b790af478 --- /dev/null +++ b/src/state/session/oauth-native-client.web.ts @@ -0,0 +1,7 @@ +export function createNativeOAuthClient() { + throw new Error('createNativeOAuthClient called on web') +} + +export function getNativeOAuthClient() { + throw new Error('getNativeOAuthClient called on web') +} diff --git a/src/state/session/oauth.tsx b/src/state/session/oauth-web-client.ts similarity index 56% rename from src/state/session/oauth.tsx rename to src/state/session/oauth-web-client.ts index a8c4eae2a3..d9dc5e11a4 100644 --- a/src/state/session/oauth.tsx +++ b/src/state/session/oauth-web-client.ts @@ -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 }