Import apps/android/src/services/login/login-flow.ts

This commit is contained in:
QQ 2026-11-14 14:18:01 +08:00
parent 5829bc1d08
commit 93c09e8d81
1 changed files with 43 additions and 0 deletions

View File

@ -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<LoginChannelContext> {
const normalized = normalizeServerUrl(baseUrl)
const publicApi = new RemoteServerApi(normalized)
await publicApi.health()
return { baseUrl: normalized, identity, publicApi }
}
signInWith<TInput>(
channel: ImmediateLoginChannel<TInput>,
context: LoginChannelContext,
input: TInput,
): Promise<LoginOutcome> {
return channel.signIn(context, input)
}
prepareRedirect(
channel: RedirectLoginChannel,
context: LoginChannelContext,
): Promise<string> {
return channel.prepareRedirect(context)
}
completeRedirect(
channel: RedirectLoginChannel,
context: LoginChannelContext,
accountToken: string,
): Promise<LoginOutcome> {
return channel.completeSignIn(context, accountToken)
}
}
export const loginFlow = new LoginFlow()