-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] #14 : Auth DataSource 구현 및 로그인 로직 구현
- Loading branch information
1 parent
11713b5
commit 1990f96
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSource.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,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> | ||
} |
46 changes: 46 additions & 0 deletions
46
core/network/src/main/java/com/wap/wapp/core/network/source/auth/AuthDataSourceImpl.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,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") | ||
} | ||
} |