-
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.
Browse files
Browse the repository at this point in the history
[Feature/#17] : 카카오 로그인, 구글 로그인 구현
- Loading branch information
Showing
21 changed files
with
700 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.sopt.noostak.di | ||
|
||
import com.sopt.noostak.BuildConfig | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Named | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object GoogleIdModule { | ||
@Provides | ||
@Singleton | ||
@Named("GoogleClientId") | ||
fun provideGoogleClientId(): String { | ||
return BuildConfig.GOOGLE_CLIENT_ID | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/sopt/noostak/di/PreferencesDataStore.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,25 @@ | ||
package com.sopt.noostak.di | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object PreferencesDataStore { | ||
private val Context.dataStore by preferencesDataStore(name = "noostak_data_store") | ||
|
||
@Singleton | ||
@Provides | ||
fun provideDataStore( | ||
@ApplicationContext context: Context | ||
): DataStore<Preferences> = | ||
context.dataStore | ||
} |
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,27 @@ | ||
package com.sopt.noostak.di | ||
|
||
import com.sopt.data.datasource.UserDataSource | ||
import com.sopt.data.datasourceimpl.UserDataSourceImpl | ||
import com.sopt.data.repositoryimpl.UserInfoRepositoryImpl | ||
import com.sopt.domain.repository.UserInfoRepository | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class UserInfoModule { | ||
@Binds | ||
@Singleton | ||
abstract fun bindsAuthDataSource( | ||
authDataSourceImpl: UserDataSourceImpl | ||
): UserDataSource | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindAuthRepository( | ||
authDataSourceImpl: UserInfoRepositoryImpl | ||
): UserInfoRepository | ||
} |
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,3 @@ | ||
package com.sopt.core.type | ||
|
||
enum class SocialType { KAKAO, GOOGLE } |
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
28 changes: 28 additions & 0 deletions
28
data/src/main/java/com/sopt/data/datasource/UserDataSource.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,28 @@ | ||
package com.sopt.data.datasource | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface UserDataSource { | ||
val accessToken: Flow<String> | ||
val refreshToken: Flow<String> | ||
val userId: Flow<Int> | ||
val isAutoLogin: Flow<Boolean> | ||
val nickName: Flow<String> | ||
val profileImage: Flow<String> | ||
|
||
suspend fun updateAccessToken(accessToken: String) | ||
|
||
suspend fun updateRefreshToken(refreshToken: String) | ||
|
||
suspend fun updateUserId(userId: Int) | ||
|
||
suspend fun updateIsAutoLogin(isAutoLogin: Boolean) | ||
|
||
suspend fun updateNickName(nickName: String) | ||
|
||
suspend fun updateProfileImage(profileImage: String) | ||
|
||
suspend fun clear() | ||
|
||
suspend fun clearForRefreshToken() | ||
} |
123 changes: 123 additions & 0 deletions
123
data/src/main/java/com/sopt/data/datasourceimpl/UserDataSourceImpl.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,123 @@ | ||
package com.sopt.data.datasourceimpl | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.emptyPreferences | ||
import androidx.datastore.preferences.core.intPreferencesKey | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import com.sopt.data.datasource.UserDataSource | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.FlowCollector | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.map | ||
import java.io.IOException | ||
import javax.inject.Inject | ||
|
||
class UserDataSourceImpl @Inject constructor( | ||
private val dataStore: DataStore<Preferences> | ||
) : UserDataSource { | ||
private object PreferencesKeys { | ||
val accessToken = stringPreferencesKey("accessToken") | ||
val refreshToken = stringPreferencesKey("refreshToken") | ||
val userId = intPreferencesKey("userId") | ||
val isAutoLogin = booleanPreferencesKey("isAutoLogin") | ||
val nickName = stringPreferencesKey("nickName") | ||
val profileImage = stringPreferencesKey("profileImage") | ||
} | ||
|
||
override val accessToken: Flow<String> = dataStore.data | ||
.catch { handleError(it) } | ||
.map { preferences -> | ||
preferences[PreferencesKeys.accessToken].orEmpty() | ||
} | ||
|
||
override val refreshToken: Flow<String> = dataStore.data | ||
.catch { handleError(it) } | ||
.map { preferences -> | ||
preferences[PreferencesKeys.refreshToken].orEmpty() | ||
} | ||
|
||
override val userId: Flow<Int> = dataStore.data | ||
.catch { handleError(it) } | ||
.map { preferences -> | ||
preferences[PreferencesKeys.userId] ?: -1 | ||
} | ||
|
||
override val isAutoLogin: Flow<Boolean> = dataStore.data | ||
.catch { handleError(it) } | ||
.map { preferences -> | ||
preferences[PreferencesKeys.isAutoLogin] ?: false | ||
} | ||
|
||
override val nickName: Flow<String> = dataStore.data | ||
.catch { handleError(it) } | ||
.map { preferences -> | ||
preferences[PreferencesKeys.nickName].orEmpty() | ||
} | ||
|
||
override var profileImage: Flow<String> = dataStore.data | ||
.catch { handleError(it) } | ||
.map { preferences -> | ||
preferences[PreferencesKeys.profileImage].orEmpty() | ||
} | ||
|
||
override suspend fun updateAccessToken(accessToken: String) { | ||
dataStore.edit { preferences -> | ||
preferences[PreferencesKeys.accessToken] = accessToken | ||
} | ||
} | ||
|
||
override suspend fun updateRefreshToken(refreshToken: String) { | ||
dataStore.edit { preferences -> | ||
preferences[PreferencesKeys.refreshToken] = refreshToken | ||
} | ||
} | ||
|
||
override suspend fun updateUserId(userId: Int) { | ||
dataStore.edit { preferences -> | ||
preferences[PreferencesKeys.userId] = userId | ||
} | ||
} | ||
|
||
override suspend fun updateIsAutoLogin(isAutoLogin: Boolean) { | ||
dataStore.edit { preferences -> | ||
preferences[PreferencesKeys.isAutoLogin] = isAutoLogin | ||
} | ||
} | ||
|
||
override suspend fun updateNickName(nickName: String) { | ||
dataStore.edit { preferences -> | ||
preferences[PreferencesKeys.nickName] = nickName | ||
} | ||
} | ||
|
||
override suspend fun updateProfileImage(profileImage: String) { | ||
dataStore.edit { preferences -> | ||
preferences[PreferencesKeys.profileImage] = profileImage | ||
} | ||
} | ||
|
||
override suspend fun clear() { | ||
dataStore.edit { preferences -> | ||
preferences.clear() | ||
} | ||
} | ||
|
||
override suspend fun clearForRefreshToken() { | ||
dataStore.edit { preferences -> | ||
preferences.remove(PreferencesKeys.accessToken) | ||
preferences.remove(PreferencesKeys.refreshToken) | ||
preferences.remove(PreferencesKeys.isAutoLogin) | ||
} | ||
} | ||
} | ||
|
||
private suspend fun FlowCollector<Preferences>.handleError(it: Throwable) { | ||
if (it is IOException) { | ||
emit(emptyPreferences()) | ||
} else { | ||
throw it | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
data/src/main/java/com/sopt/data/repositoryimpl/UserInfoRepositoryImpl.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,54 @@ | ||
package com.sopt.data.repositoryimpl | ||
|
||
import com.sopt.data.datasource.UserDataSource | ||
import com.sopt.domain.repository.UserInfoRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import javax.inject.Inject | ||
|
||
class UserInfoRepositoryImpl @Inject constructor( | ||
private val authDataSource: UserDataSource | ||
) : UserInfoRepository { | ||
override fun getAccessToken(): Flow<String> = authDataSource.accessToken | ||
|
||
override fun getRefreshToken(): Flow<String> = authDataSource.refreshToken | ||
|
||
override fun getUserId(): Flow<Int> = authDataSource.userId | ||
|
||
override fun getIsAutoLogin(): Flow<Boolean> = authDataSource.isAutoLogin | ||
|
||
override fun getNickName(): Flow<String> = authDataSource.nickName | ||
|
||
override fun getProfileImage(): Flow<String> = authDataSource.profileImage | ||
|
||
override suspend fun saveAccessToken(accessToken: String) { | ||
authDataSource.updateAccessToken(accessToken) | ||
} | ||
|
||
override suspend fun saveRefreshToken(refreshToken: String) { | ||
authDataSource.updateRefreshToken(refreshToken) | ||
} | ||
|
||
override suspend fun saveUserId(userId: Int) { | ||
authDataSource.updateUserId(userId) | ||
} | ||
|
||
override suspend fun saveIsAutoLogin(isAutoLogin: Boolean) { | ||
authDataSource.updateIsAutoLogin(isAutoLogin) | ||
} | ||
|
||
override suspend fun saveNickName(nickName: String) { | ||
authDataSource.updateNickName(nickName) | ||
} | ||
|
||
override suspend fun saveProfileImage(profileImage: String) { | ||
authDataSource.updateProfileImage(profileImage) | ||
} | ||
|
||
override suspend fun clearAll() { | ||
authDataSource.clear() | ||
} | ||
|
||
override suspend fun clearForRefreshToken() { | ||
authDataSource.clearForRefreshToken() | ||
} | ||
} |
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,10 @@ | ||
package com.sopt.domain.entity | ||
|
||
data class UserEntity( | ||
val accessToken: String?, | ||
val refreshToken: String?, | ||
val userId: Int?, | ||
val isAutoLogin: Boolean, | ||
val nickName: String, | ||
val profileImage: String? | ||
) |
Oops, something went wrong.