Skip to content

Commit ba90b45

Browse files
committed
docs: update README with async WebCrypto encryption guidance for KSafe
1 parent 9e35a75 commit ba90b45

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,31 @@ actual val platformModule = module {
109109
}
110110
```
111111

112+
> **WASM/JS:** WebCrypto encryption is async-only, so KSafe must finish decrypting its cache before your UI reads any encrypted values. Call `awaitCacheReady()` after Koin is initialized but before rendering content. In a Compose for Web app, the recommended pattern is:
113+
>
114+
> ```kotlin
115+
> fun main() {
116+
> val body = document.body ?: return
117+
> ComposeViewport(body) {
118+
> KoinMultiplatformApplication(config = createKoinConfiguration()) {
119+
> var cacheReady by remember { mutableStateOf(false) }
120+
>
121+
> LaunchedEffect(Unit) {
122+
> val ksafe: KSafe = getKoin().get()
123+
> ksafe.awaitCacheReady()
124+
> cacheReady = true
125+
> }
126+
>
127+
> if (cacheReady) {
128+
> AppContent() // your app's UI
129+
> }
130+
> }
131+
> }
132+
> }
133+
> ```
134+
>
135+
> Koin must be running before `getKoin().get()` can retrieve KSafe, so `awaitCacheReady()` goes **inside** `KoinMultiplatformApplication`, not before it.
136+
112137
Now you're ready to inject KSafe into your ViewModels!
113138
114139
***

0 commit comments

Comments
 (0)