Skip to content

Commit

Permalink
[FEATURE] #14 : Auth DataSource 구현 및 로그인 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Oct 5, 2023
1 parent 11713b5 commit 1990f96
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<String>

suspend fun signUp(signUpRequest: SignUpRequest): Result<Unit>

suspend fun signOut(): Result<Unit>

suspend fun resign(): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -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<String> {
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<Unit> {
TODO("Not yet implemented")
}

override suspend fun signOut(): Result<Unit> {
TODO("Not yet implemented")
}

override suspend fun resign(): Result<Unit> {
TODO("Not yet implemented")
}
}

0 comments on commit 1990f96

Please sign in to comment.