Skip to content

Commit

Permalink
Merge pull request #117 from yy0ung/feature/aos-mypage
Browse files Browse the repository at this point in the history
[MyPage/aos] 로그아웃, 회원 탈퇴 후 화면 전환
  • Loading branch information
plashdof authored Nov 26, 2023
2 parents eede3be + 27c9f24 commit 7ba9643
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Aos/app/src/main/java/com/avengers/nibobnebob/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class App : Application(){

init {
instance = this
}

override fun onCreate() {
super.onCreate()
initializeNaverSDK()
}

companion object{
lateinit var instance : App
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = APP_NAME)
fun getContext(): Context = instance.applicationContext
}

private fun initializeNaverSDK(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.avengers.nibobnebob.config

import android.util.Log
import com.avengers.nibobnebob.app.DataStoreManager
import com.avengers.nibobnebob.presentation.util.Constants.ACCESS
import com.avengers.nibobnebob.presentation.util.Constants.AUTHORIZATION
import com.avengers.nibobnebob.presentation.util.Constants.BEARER
import kotlinx.coroutines.flow.first
Expand All @@ -18,11 +16,10 @@ class AccessTokenInterceptor @Inject constructor(private val dataStoreManager: D
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {

// 동기가 아닌 비동기로 불러와야한다.. runBlocking말고 다른 방안에 대해 고민
val accessToken = runBlocking {
dataStoreManager.getAccessToken().first()
}
Log.d("토큰 테스트",accessToken.toString())

val builder: Request.Builder = chain.request().newBuilder()
accessToken?.takeIf { it.isNotEmpty() }?.let {
builder.addHeader(AUTHORIZATION, "$BEARER $it")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.avengers.nibobnebob.config


import android.content.Intent
import com.avengers.nibobnebob.app.App
import com.avengers.nibobnebob.app.DataStoreManager
import com.avengers.nibobnebob.data.model.BaseState
import com.avengers.nibobnebob.data.model.request.RefreshTokenRequest
import com.avengers.nibobnebob.data.model.response.BaseResponse
import com.avengers.nibobnebob.data.model.response.NaverLoginResponse
import com.avengers.nibobnebob.data.model.runRemote
import com.avengers.nibobnebob.data.remote.RefreshApi
import com.avengers.nibobnebob.presentation.ui.intro.IntroActivity
import com.avengers.nibobnebob.presentation.util.Constants
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -48,11 +51,15 @@ class BearerInterceptor @Inject constructor(
else -> {
dataStoreManager.deleteAccessToken()
dataStoreManager.deleteRefreshToken()

val intent = Intent(App.getContext(), IntroActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
App.getContext().startActivity(intent)
}
}
}
}
(newAccessToken)?.let {
newAccessToken?.let {
val newRequest = originalRequest.newBuilder()
.addHeader(AUTHORIZATION, "$BEARER $newAccessToken")
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.avengers.nibobnebob.data.model.response.MyDefaultInfoResponse
import com.avengers.nibobnebob.data.model.response.MyInfoResponse
import com.avengers.nibobnebob.data.model.runRemote
import com.avengers.nibobnebob.data.remote.MyPageApi
import com.navercorp.nid.oauth.NidOAuthLogin
import com.navercorp.nid.oauth.OAuthLoginCallback
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject
Expand Down Expand Up @@ -43,6 +45,15 @@ class MyPageRepositoryImpl @Inject constructor(
is BaseState.Success -> {
dataStoreManager.deleteAccessToken()
dataStoreManager.deleteRefreshToken()

NidOAuthLogin().callDeleteTokenApi(object : OAuthLoginCallback{
override fun onError(errorCode: Int, message: String) {}

override fun onFailure(httpStatus: Int, message: String) {}

override fun onSuccess() {}
})

emit(result)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class MyPageFragment : BaseFragment<FragmentMyPageBinding>(R.layout.fragment_my_
viewModel.events.collect { event ->
when (event) {
is MyEditPageEvent.NavigateToIntro -> {
(activity as MainActivity).finish()
val intent = Intent(context, IntroActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
}
}
Expand All @@ -76,7 +76,6 @@ class MyPageFragment : BaseFragment<FragmentMyPageBinding>(R.layout.fragment_my_
}

private fun withDrawConfirm() {
Log.d("TEST", "탈퇴 완료")
viewModel.withdraw()
}

Expand Down

0 comments on commit 7ba9643

Please sign in to comment.