This commit is contained in:
Trey t
2025-11-04 10:51:20 -06:00
parent 78c62cfc52
commit de1c7931e9
21 changed files with 1645 additions and 87 deletions

View File

@@ -2,8 +2,13 @@ package com.example.mycrib
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import com.mycrib.storage.TokenManager
import com.mycrib.storage.TokenStorage
fun main() = application {
// Initialize TokenStorage with JVM TokenManager
TokenStorage.initialize(TokenManager.getInstance())
Window(
onCloseRequest = ::exitApplication,
title = "MyCrib",

View File

@@ -0,0 +1,38 @@
package com.mycrib.storage
import java.util.prefs.Preferences
/**
* JVM implementation of TokenManager using Java Preferences API.
*/
actual class TokenManager {
private val prefs: Preferences = Preferences.userRoot().node(PREFS_NODE)
actual fun saveToken(token: String) {
prefs.put(KEY_TOKEN, token)
prefs.flush()
}
actual fun getToken(): String? {
return prefs.get(KEY_TOKEN, null)
}
actual fun clearToken() {
prefs.remove(KEY_TOKEN)
prefs.flush()
}
companion object {
private const val PREFS_NODE = "com.mycrib.app"
private const val KEY_TOKEN = "auth_token"
@Volatile
private var instance: TokenManager? = null
fun getInstance(): TokenManager {
return instance ?: synchronized(this) {
instance ?: TokenManager().also { instance = it }
}
}
}
}