Skip to content

Prepare

Vadym Yaroshchuk edited this page Feb 26, 2024 · 7 revisions

Adding dependency

1. Add TimeMates Maven to your build script:

repositories {
    maven("https://maven.timemates.org/releases")
}

2. Add the dependency:

dependencies {
    commonMainImplementation("org.timemates.credentials:credentials-manager:1.0.0")
}

Constructing instance

Create a common factory class or method to obtain a CredentialsStorage instance.

// common
expect class CredentialsStorageFactory {
    fun create(): CredentialsStorage
}
// Android
actual class CredentialsStorageFactory(val context: Context) {
    actual fun create(): CredentialsStorage {
        return AndroidEncryptedPrefsCredentials(context)
    }
}
// Desktop
actual class CredentialsStorageFactory {
    actual fun create(): CredentialsStorage {
        return DesktopCredentialsStorage(context)
    }
}
// Js
actual class CredentialsStorageFactory {
    actual fun create(): CredentialsStorage {
        return JsLocalCredentialsStorage()
    }
}

And now, you can go to Usage examples.

Clone this wiki locally