diff --git a/apps/android/src/services/login/login-flow.ts b/apps/android/src/services/login/login-flow.ts new file mode 100644 index 0000000..cfa3f23 --- /dev/null +++ b/apps/android/src/services/login/login-flow.ts @@ -0,0 +1,43 @@ +import { normalizeServerUrl } from '../../lib/server-url' +import type { DeviceIdentity } from '../../types' +import { RemoteServerApi } from '../api' +import type { + ImmediateLoginChannel, + LoginChannelContext, + LoginOutcome, + RedirectLoginChannel, +} from './types' + +export class LoginFlow { + async createContext(baseUrl: string, identity: DeviceIdentity): Promise { + const normalized = normalizeServerUrl(baseUrl) + const publicApi = new RemoteServerApi(normalized) + await publicApi.health() + return { baseUrl: normalized, identity, publicApi } + } + + signInWith( + channel: ImmediateLoginChannel, + context: LoginChannelContext, + input: TInput, + ): Promise { + return channel.signIn(context, input) + } + + prepareRedirect( + channel: RedirectLoginChannel, + context: LoginChannelContext, + ): Promise { + return channel.prepareRedirect(context) + } + + completeRedirect( + channel: RedirectLoginChannel, + context: LoginChannelContext, + accountToken: string, + ): Promise { + return channel.completeSignIn(context, accountToken) + } +} + +export const loginFlow = new LoginFlow()