Files
standardnotes-app-web/packages/snjs/lib/Domain/UseCase/GetRecoveryCodes/GetRecoveryCodes.ts
Karol Sójko 896834f65a chore(web): put sign-in email notifications setting under paywall (#2249)
* chore: upgrade setting names to value objects

* chore(web): put sign-in email notifications setting under paywall

* chore: fix using setting name value objects in mocha tests

* chore: fix wording on email notifications titles
2023-03-08 12:53:59 +01:00

26 lines
990 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.create(SettingName.NAMES.RecoveryCodes).getValue(),
)
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)
}
}