Files
standardnotes-app-web/packages/snjs/lib/Domain/UseCase/GetRecoveryCodes/GetRecoveryCodes.ts
Karol Sójko 5e6c901c21 feat: recovery codes UI (recovery sign in + get recovery codes) (#2139)
* feat(web): show recovery codes

* feat(web): add recovery sign in

* fix: copy

* fix: styles

* feat: add "copy to clipboard" button

* style: copy

* fix: copy button bg

* style: singularize recovery codes

* style: singularize recovery codes

* feat: password validation

Co-authored-by: Aman Harwara <amanharwara@protonmail.com>
Co-authored-by: Mo <mo@standardnotes.com>
2023-01-10 21:33:44 +01:00

24 lines
940 B
TypeScript

import { AuthClientInterface } from '@standardnotes/services'
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
import { SettingName } from '@standardnotes/settings'
import { SettingsClientInterface } from '@Lib/Services/Settings/SettingsClientInterface'
export class GetRecoveryCodes implements UseCaseInterface<string> {
constructor(private authClient: AuthClientInterface, private settingsClient: SettingsClientInterface) {}
async execute(): Promise<Result<string>> {
const existingRecoveryCodes = await this.settingsClient.getSetting(SettingName.RecoveryCodes)
if (existingRecoveryCodes !== undefined) {
return Result.ok(existingRecoveryCodes)
}
const generatedRecoveryCodes = await this.authClient.generateRecoveryCodes()
if (generatedRecoveryCodes === false) {
return Result.fail('Could not generate recovery code')
}
return Result.ok(generatedRecoveryCodes)
}
}