Skip to content

Commit

Permalink
chore: 소셜로그인, 로컬로그인 시 에러 ui 추가
Browse files Browse the repository at this point in the history
- Applied
when(viewModel.loginStatusCode){
        401 -> "이메일 또는 비밀번호가 잘못되었습니다."
        403 -> "권한이 존재하지 않습니다."
        409 -> "중복된 이메일 계정이 존재합니다."
        else -> viewModel.loginStatusCode.toString()
    }
  • Loading branch information
kkh725 committed Aug 15, 2024
1 parent 86ebe42 commit 211f7a6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 10 deletions.
17 changes: 14 additions & 3 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
applicationId = "com.echoist.linkedout"
minSdk = 26
targetSdk = 34
versionCode = 1
versionCode = 3 //todo 릴리즈 생성마다 +1
versionName = "1.0.0"
//git ignore 용입니다.
//구글 네이티브 앱 키
Expand Down
51 changes: 50 additions & 1 deletion app/src/main/java/com/echoist/linkedout/page/login/LoginPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
Expand Down Expand Up @@ -143,6 +151,7 @@ import com.navercorp.nid.NaverIdLoginSDK
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import java.net.URLDecoder
import java.nio.charset.StandardCharsets

Expand Down Expand Up @@ -187,7 +196,7 @@ class LoginPage : ComponentActivity() {
Log.d("Hash", keyHash)
val navController = rememberNavController()

NavHost(navController = navController, startDestination = Routes.LoginPage) {
NavHost(navController = navController, startDestination = Routes.OnBoarding) {
composable(Routes.OnBoarding) {
OnBoardingPage(navController)
}
Expand Down Expand Up @@ -507,6 +516,17 @@ fun LoginPage(
LaunchedEffect(key1 = Unit) {
viewModel.requestAppVersion()
}

LaunchedEffect(key1 = viewModel.loginStatusCode) {
delay(1000)
viewModel.loginStatusCode = 200
}
val errorText = when(viewModel.loginStatusCode){
401 -> "이메일 또는 비밀번호가 잘못되었습니다."
403 -> "권한이 존재하지 않습니다."
409 -> "중복된 이메일 계정이 존재합니다."
else -> viewModel.loginStatusCode.toString()
}

LinkedOutTheme {
Scaffold(
Expand Down Expand Up @@ -609,6 +629,32 @@ fun LoginPage(
SocialLoginBar(navController, viewModel)
Spacer(modifier = Modifier.height(20.dp))
}
//에러 박스
AnimatedVisibility(
visible = viewModel.loginStatusCode >= 400,
enter = fadeIn(animationSpec = tween(durationMillis = 500,easing = FastOutSlowInEasing)),
exit = fadeOut(animationSpec = tween(durationMillis = 0, easing = LinearEasing))
)
{
Box(modifier = Modifier
.fillMaxSize()
.background(Color.Black.copy(0.7f))){
Box(modifier = Modifier.fillMaxWidth().align(Alignment.Center).
height(60.dp).padding(horizontal = 20.dp).background(
Color(0xFFE43446),
shape = RoundedCornerShape(10)
)){
Text(
text = errorText,
color = Color.White,
modifier = Modifier.align(
Alignment.Center
)
)
}

}
}
}
)
}
Expand Down Expand Up @@ -742,6 +788,7 @@ fun LoginBtn(
val interactionSource = remember { MutableInteractionSource() }
// val isPressed by interactionSource.collectIsPressedAsState()
val error = viewModel.userId.isEmpty() || viewModel.userPw.isEmpty()


LinkedOutTheme {
Button(
Expand All @@ -761,6 +808,8 @@ fun LoginBtn(
) {
Text(text = "로그인")
}


}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class SocialLoginViewModel @Inject constructor(
}
}

var loginStatusCode by mutableStateOf(200)
//로그인
fun login(navController: NavController) {
viewModelScope.launch {
Expand All @@ -120,15 +121,16 @@ class SocialLoginViewModel @Inject constructor(
if (response.isSuccessful) {
Log.i("server header token", response.headers()["authorization"].toString())
Token.accessToken = (response.headers()["authorization"].toString())
Log.d("authApiSuccess3", "로그인 성공! ${response.headers()["authorization"]}") // 이값을 항상 헤더에 넣을것.
loginStatusCode = response.code()
navController.popBackStack("OnBoarding", false) //onboarding까지 전부 삭제.

if (response.code() == 202) // 탈퇴유저. 첫유저일리 없고 정보읽지않고 홈으로이동.
navController.navigate("HOME/${response.code()}")

else readMyInfo(navController)// 첫 회원가입 여부 확인하고 화면이동
} else {
Log.e("login_failed", "${response.code()}")
loginStatusCode = response.code()
Log.e("login_failed", "$loginStatusCode")
Log.e("login_failed", response.message())

}
Expand Down Expand Up @@ -231,12 +233,13 @@ class SocialLoginViewModel @Inject constructor(
Token.accessToken = (response.headers()["authorization"].toString())
Log.i("server header token(구글)", Token.accessToken)
Log.d("응답코드로 탈퇴/밴 사용자 여부파악 202 -> 탈퇴신청유저 ", response.code().toString())

loginStatusCode = response.code()
if (response.code() == 202) // 탈퇴유저. 첫유저일리 없고 정보읽지않고 홈으로이동.
navController.navigate("HOME/${response.code()}")

else readMyInfo(navController)// 첫 회원가입 여부 확인하고 화면이동
} else { //409는 중복. 502는 아예 서버 팅
loginStatusCode = response.code()
Log.e("google_login 서버와 api", "Failed ${response.code()}")
}

Expand Down Expand Up @@ -326,6 +329,7 @@ class SocialLoginViewModel @Inject constructor(
Log.i("server header token(카카오)", response.headers()["authorization"].toString())
Token.accessToken = (response.headers()["authorization"].toString())
Log.d(TAG, "requestKakaoLogin: ${response.code()}")
loginStatusCode = response.code()

if (response.code() == 202) // 탈퇴유저. 첫유저일리 없고 정보읽지않고 홈으로이동.
navController.navigate("HOME/${response.code()}")
Expand All @@ -335,6 +339,7 @@ class SocialLoginViewModel @Inject constructor(

} else {
Log.e("kakao_login 서버와 api", "Failed ${response.code()}")
loginStatusCode = response.code()
}

} catch (e: Exception) {
Expand Down Expand Up @@ -450,14 +455,15 @@ class SocialLoginViewModel @Inject constructor(
Log.i("server header token(네이버)", response.headers()["authorization"].toString())
Token.accessToken = (response.headers()["authorization"].toString())
Log.d(TAG, "requestNaverLogin: ${response.code()}")

loginStatusCode = response.code()

if (response.code() == 202) // 탈퇴유저. 첫유저일리 없고 정보읽지않고 홈으로이동.
navController.navigate("HOME/${response.code()}")

else readMyInfo(navController)// 첫 회원가입 여부 확인하고 화면이동

} else {
loginStatusCode = response.code()
Log.e("naver_login 서버와 api", "Failed ${response.code()}")
}

Expand Down Expand Up @@ -553,14 +559,15 @@ class SocialLoginViewModel @Inject constructor(
Log.i("server header token(애플)", response.headers()["authorization"].toString())
Token.accessToken = (response.headers()["authorization"].toString())
Log.d(TAG, "requestAppleLogin: ${response.code()}")

loginStatusCode = response.code()
if (response.code() == 202) // 탈퇴유저. 첫유저일리 없고 정보읽지않고 홈으로이동.
navController.navigate("HOME/${response.code()}")


else readMyInfo(navController)// 첫 회원가입 여부 확인하고 화면이동

} else {
loginStatusCode = response.code()
Log.e("Apple_login 서버와 api", "Failed ${response.code()}")
}

Expand Down

0 comments on commit 211f7a6

Please sign in to comment.