diff --git a/android/app/src/main/java/by/eapp/musicroom/MainActivity.kt b/android/app/src/main/java/by/eapp/musicroom/MainActivity.kt index 0fdae8d..c277a46 100644 --- a/android/app/src/main/java/by/eapp/musicroom/MainActivity.kt +++ b/android/app/src/main/java/by/eapp/musicroom/MainActivity.kt @@ -4,19 +4,8 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge -import androidx.activity.viewModels -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Scaffold -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview import androidx.navigation.compose.rememberNavController import by.eapp.musicroom.navigation.NavHostController -import by.eapp.musicroom.screens.test.TestScreen -import by.eapp.musicroom.screens.test.TestViewModel -import by.eapp.musicroom.ui.theme.MusicRoomTheme import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint diff --git a/android/app/src/main/java/by/eapp/musicroom/data/AuthAuthenticator.kt b/android/app/src/main/java/by/eapp/musicroom/data/AuthAuthenticator.kt new file mode 100644 index 0000000..e207b73 --- /dev/null +++ b/android/app/src/main/java/by/eapp/musicroom/data/AuthAuthenticator.kt @@ -0,0 +1,67 @@ +package by.eapp.musicroom.data + +import by.eapp.musicroom.domain.model.RegistrationData +import by.eapp.musicroom.domain.model.SubmitData +import by.eapp.musicroom.domain.repo.login.AuthorizationService +import by.eapp.musicroom.domain.repo.login.JwtTokenManager +import by.eapp.musicroom.network.ApiService +import okhttp3.Authenticator +import javax.inject.Inject + +class AuthAuthenticator @Inject constructor( + private val tokenManager: JwtTokenManager, + private val apiService: ApiService, +) : Authenticator, AuthorizationService { + + companion object { + const val HEADER_AUTHORIZATION = "Authorization" + const val TOKEN_TYPE = "Bearer" + } + + +// override fun authenticate(route: Route?, response: Response): Request? { +// val currentToken = runBlocking { +// tokenManager.getAccessJwt() +// } +// synchronized(this) { +// val updatedToken = runBlocking { +// tokenManager.getAccessJwt() +// } +// val token = if (currentToken != updatedToken) updatedToken else { +// val newSessionResponse = runBlocking { apiService.refreshToken("") } +// if (newSessionResponse.isSuccessful && newSessionResponse.body() != null) { +// newSessionResponse.body()?.let { body -> +// runBlocking { +// tokenManager.saveAccessJwt(body.accessToken) +// tokenManager.saveRefreshJwt(body.refreshToken) +// } +// body.accessToken +// } +// } else null +// } +// return if (token != null) response.request.newBuilder() +// .header(HEADER_AUTHORIZATION, "$token") +// .build() else null +// } +// } + + override suspend fun registerUser(registrationData: RegistrationData) { + TODO("Not yet implemented") + } + + override suspend fun loginUser(login: String, password: String) { + TODO("Not yet implemented") + } + + override suspend fun sendCode(userId: Int) { + TODO("Not yet implemented") + } + + override suspend fun submitCode(submitData: SubmitData) { + TODO("Not yet implemented") + } + + override suspend fun refreshToken(refreshToken: String) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/android/app/src/main/java/by/eapp/musicroom/domain/repo/login/AuthorizationService.kt b/android/app/src/main/java/by/eapp/musicroom/domain/repo/login/AuthorizationService.kt new file mode 100644 index 0000000..6a28b2e --- /dev/null +++ b/android/app/src/main/java/by/eapp/musicroom/domain/repo/login/AuthorizationService.kt @@ -0,0 +1,12 @@ +package by.eapp.musicroom.domain.repo.login + +import by.eapp.musicroom.domain.model.RegistrationData +import by.eapp.musicroom.domain.model.SubmitData + +interface AuthorizationService { + suspend fun registerUser(registrationData: RegistrationData) + suspend fun loginUser(login: String, password: String) + suspend fun sendCode(userId: Int) + suspend fun submitCode(submitData: SubmitData) + suspend fun refreshToken(refreshToken: String) +} \ No newline at end of file