@@ -24,15 +24,20 @@ package org.astermail.android.auth
2424import androidx.lifecycle.ViewModel
2525import androidx.lifecycle.viewModelScope
2626import android.content.Context
27+ import android.widget.Toast
2728import dagger.hilt.android.lifecycle.HiltViewModel
2829import dagger.hilt.android.qualifiers.ApplicationContext
2930import javax.inject.Inject
3031import kotlinx.coroutines.CancellationException
32+ import kotlinx.coroutines.Dispatchers
3133import kotlinx.coroutines.flow.MutableStateFlow
3234import kotlinx.coroutines.flow.StateFlow
3335import kotlinx.coroutines.flow.asStateFlow
3436import kotlinx.coroutines.launch
37+ import kotlinx.coroutines.withContext
3538import kotlinx.coroutines.withTimeoutOrNull
39+ import org.astermail.android.BuildConfig
40+ import org.astermail.android.R
3641import org.astermail.android.api.auth.AuthApi
3742import org.astermail.android.security.LockdownStore
3843
@@ -54,6 +59,21 @@ class AuthGateViewModel @Inject constructor(
5459 }
5560 _is_ready .value = true
5661 if (auth_repository.is_signed_in.value) {
62+ viewModelScope.launch {
63+ val csrf_ok = auth_repository.ensure_csrf_ready()
64+ if (! csrf_ok) {
65+ if (BuildConfig .DEBUG ) {
66+ android.util.Log .w(" AuthGate" , " CSRF token fetch failed on launch" )
67+ }
68+ withContext(Dispatchers .Main ) {
69+ Toast .makeText(
70+ context,
71+ context.getString(R .string.csrf_unavailable),
72+ Toast .LENGTH_LONG ,
73+ ).show()
74+ }
75+ }
76+ }
5777 viewModelScope.launch {
5878 try {
5979 val info = withTimeoutOrNull(8_000L ) { auth_api.me() }
0 commit comments