From 1990f96e68b372a933b10a41034d7b2163e6f333 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Thu, 5 Oct 2023 12:30:56 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20#14=20:=20Auth=20DataSource=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../network/source/auth/AuthDataSource.kt | 15 ++++++ .../network/source/auth/AuthDataSourceImpl.kt | 46 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSource.kt create mode 100644 core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSourceImpl.kt diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSource.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSource.kt new file mode 100644 index 00000000..07f338f5 --- /dev/null +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSource.kt @@ -0,0 +1,15 @@ +package com.wap.wapp.core.network.source.auth + +import com.wap.wapp.core.network.model.auth.SignUpRequest + +interface AuthDataSource { + suspend fun hasPendingResult(): Boolean + + suspend fun signIn(email: String): Result + + suspend fun signUp(signUpRequest: SignUpRequest): Result + + suspend fun signOut(): Result + + suspend fun resign(): Result +} \ No newline at end of file diff --git a/core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSourceImpl.kt b/core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSourceImpl.kt new file mode 100644 index 00000000..6efff89c --- /dev/null +++ b/core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSourceImpl.kt @@ -0,0 +1,46 @@ +package com.wap.wapp.core.network.source.auth + +import android.app.Activity +import android.content.Context +import com.google.firebase.auth.FirebaseAuth +import com.google.firebase.auth.OAuthProvider +import com.wap.wapp.core.network.model.auth.SignUpRequest +import com.wap.wapp.core.network.utils.await +import dagger.hilt.android.qualifiers.ActivityContext +import javax.inject.Inject + +class AuthDataSourceImpl @Inject constructor( + private val firebaseAuth: FirebaseAuth, + @ActivityContext private val context: Context +): AuthDataSource { + override suspend fun hasPendingResult(): Boolean { + return firebaseAuth.pendingAuthResult != null + } + + override suspend fun signIn(email: String): Result { + return runCatching { + val provider = OAuthProvider.newBuilder("github.com") + provider.addCustomParameter("login", email) + + val activityContext = context as Activity + + val result = firebaseAuth.startActivityForSignInWithProvider( + activityContext, provider.build() + ).await() + + checkNotNull(result.user).uid + } + } + + override suspend fun signUp(signUpRequest: SignUpRequest): Result { + TODO("Not yet implemented") + } + + override suspend fun signOut(): Result { + TODO("Not yet implemented") + } + + override suspend fun resign(): Result { + TODO("Not yet implemented") + } +}