-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 카카오 토큰 서버에 저장 2. jwt토큰 받아와 로컬에 저장
- Loading branch information
tnvnfdla12
committed
Nov 20, 2022
1 parent
0626763
commit e8cd963
Showing
24 changed files
with
218 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/ftw/hometerview/ui/login/LoginViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.ftw.hometerview.ui.login | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.ViewModel | ||
import com.ftw.domain.entity.KakaoToken | ||
import com.ftw.domain.usecase.login.LoginUseCase | ||
import com.ftw.hometerview.dispatcher.Dispatcher | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
|
||
class LoginViewModel( | ||
private val dispatcher: Dispatcher, | ||
private val loginUseCase: LoginUseCase | ||
) : ViewModel() { | ||
|
||
sealed class State { | ||
object Success : State() | ||
object Failure : State() | ||
object Loading : State() | ||
} | ||
|
||
private val _state: MutableStateFlow<State> = MutableStateFlow(State.Loading) | ||
val state: StateFlow<State> get() = _state.asStateFlow() | ||
|
||
//등록된 회원인지 아닌지 여부랑 아니면 등록까지 시켜주기 | ||
fun setKakaoToken(kakaoToken: KakaoToken){ | ||
_state.value = State.Loading | ||
CoroutineScope(dispatcher.ui()).launch { | ||
val result: Result<Boolean> = loginUseCase.signUp(kakaoToken) | ||
Log.d("adasdas",result.toString()) | ||
if(result.isSuccess){ | ||
_state.value = State.Success | ||
} else { | ||
_state.value = State.Failure | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package com.ftw.data.datasource | ||
|
||
import com.ftw.domain.entity.JWTToken | ||
import com.ftw.domain.entity.KakaoToken | ||
|
||
interface LoginDataSource { | ||
suspend fun login(token: String): Result<String> | ||
suspend fun setKakaoToken(kakaoToken: KakaoToken): Result<JWTToken> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package com.ftw.data.datasource | ||
|
||
import com.ftw.domain.entity.JWTToken | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface TokenDataSource { | ||
suspend fun set(name: String) | ||
suspend fun set(jwtToken: JWTToken) | ||
suspend fun get(): Flow<Result<String>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.ftw.data.remote.api | ||
|
||
import com.ftw.data.remote.request.KakaoTokenReq | ||
import com.ftw.data.remote.response.RemoteResponse | ||
import retrofit2.Response | ||
import retrofit2.http.* | ||
|
||
interface SignUpAPI { | ||
|
||
@POST("/api/v1/auth/login/kakao") | ||
suspend fun create( | ||
@Body kakaoTokenReq: KakaoTokenReq | ||
): Response<RemoteResponse<Nothing>> | ||
} |
27 changes: 23 additions & 4 deletions
27
data/src/main/java/com/ftw/data/remote/datasource/LoginRemoteDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
package com.ftw.data.remote.datasource | ||
|
||
import com.ftw.data.datasource.LoginDataSource | ||
import com.ftw.data.remote.api.LoginAPI | ||
import com.ftw.data.remote.api.SignUpAPI | ||
import com.ftw.data.remote.exception.ResponseException | ||
import com.ftw.data.remote.request.KakaoTokenReq | ||
import com.ftw.domain.entity.JWTToken | ||
import com.ftw.domain.entity.KakaoToken | ||
|
||
class LoginRemoteDataSource(private val api: LoginAPI) : LoginDataSource { | ||
override suspend fun login(token: String): Result<String> { | ||
return Result.success("") | ||
class LoginRemoteDataSource(private val api: SignUpAPI) : LoginDataSource { | ||
override suspend fun setKakaoToken(kakaoToken: KakaoToken): Result<JWTToken> { | ||
return try { | ||
val response = api.create(KakaoTokenReq(kakaoToken.accessToken,kakaoToken.refreshToken)) | ||
if (response.isSuccessful) { | ||
val accessToken = response.headers().get("Authorization-Access-Token") | ||
val refreshToken = response.headers().get("Authorization-Refresh-Token") | ||
if(accessToken != null && refreshToken != null){ | ||
return Result.success(JWTToken(accessToken,refreshToken)) | ||
}else { | ||
throw ResponseException("Token is Null Exception") | ||
} | ||
} else { | ||
throw ResponseException("Network Exception") | ||
} | ||
} catch (e : Exception) { | ||
return Result.failure(e) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
data/src/main/java/com/ftw/data/remote/request/KakaoTokenReq.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.ftw.data.remote.request | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class KakaoTokenReq ( | ||
@SerializedName("accessToken") val accessToken : String, | ||
@SerializedName("refreshToken") val refreshToken : String | ||
) |
Oops, something went wrong.