* 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
26 lines
990 B
TypeScript
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)
|
|
}
|
|
}
|