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") + } +}