Skip to content

Commit

Permalink
#3 added AuthorizationService(TODO: build logic for authenticate) + M…
Browse files Browse the repository at this point in the history
…ainActivity changes
  • Loading branch information
nastix123 committed Jul 14, 2024
1 parent dcca0d4 commit 4284340
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 11 deletions.
11 changes: 0 additions & 11 deletions android/app/src/main/java/by/eapp/musicroom/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 4284340

Please sign in to comment.