diff --git a/app/src/main/java/com/example/mhnfe/ui/screens/auth/login/LoginViewModel.kt b/app/src/main/java/com/example/mhnfe/ui/screens/auth/login/LoginViewModel.kt index 16cb7a78..54b54842 100644 --- a/app/src/main/java/com/example/mhnfe/ui/screens/auth/login/LoginViewModel.kt +++ b/app/src/main/java/com/example/mhnfe/ui/screens/auth/login/LoginViewModel.kt @@ -1,7 +1,9 @@ package com.example.mhnfe.ui.screens.auth.login +import android.content.Context import android.content.SharedPreferences import android.util.Log +import android.widget.Toast import androidx.datastore.core.DataStore import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -14,6 +16,7 @@ import com.example.mhnfe.data.remote.response.RefreshToken import com.example.mhnfe.data.remote.response.SendPasswordResponse import com.example.mhnfe.data.repository.AuthRepository import dagger.hilt.android.lifecycle.HiltViewModel +import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.first @@ -30,7 +33,8 @@ class LoginViewModel @Inject constructor( private val refreshTokenDataStore: DataStore, private val groupIdDataStore: DataStore, private val memberIdDataStore: DataStore, - private val sharedPreferences: SharedPreferences + private val sharedPreferences: SharedPreferences, + @ApplicationContext private val context: Context ) : ViewModel() { // 로그인 결과 상태 @@ -98,11 +102,16 @@ class LoginViewModel @Inject constructor( _errorMessage.value = "네트워크 오류가 발생했습니다. 인터넷 연결을 확인해주세요." } catch (e: HttpException) { when (e.code()) { - 400, 404 -> { + 400 -> { _errorMessage.value = "잘못된 아이디 또는 비밀번호입니다." Log.e("LoginViewModel", "Error: ${_errorMessage.value}") } + 404 -> { + _errorMessage.value = "회원 정보를 찾을 수 없습니다." + Log.e("LoginViewModel", "Error: ${_errorMessage.value}") + } + else -> { Log.e("LoginViewModel", "HttpException: ${e.message}") _errorMessage.value = "서버 오류가 발생했습니다. 다시 시도해주세요." @@ -182,6 +191,7 @@ class LoginViewModel @Inject constructor( if(response.result.code == 200) { _sendPasswordResponse.value = response _errorMessage.value = null + Toast.makeText(context, "임시 비밀번호가 메일로 전송되었습니다.", Toast.LENGTH_SHORT).show() } else { _errorMessage.value = mapErrorMessage( response.result.code,