/
Jojer
/
RepTrack
Обзор
Документация
Войти
/
Jojer
/
RepTrack
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
app/src/main/java/com/example/reptrack/data/auth/FirebaseAuthDataSource.kt
43 строки
2 KB
Maxim Odintsov
profile
07 июн 2026, 15:53
07 июн 2026, 15:53
3bafb0c
Код
Авторство
О чём код?
package com.example.reptrack.data.auth import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseUser import com.google.firebase.auth.GoogleAuthProvider import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.tasks.await class FirebaseAuthDataSource( private val firebaseAuth: FirebaseAuth ) { suspend fun signUp(email: String, password: String): FirebaseUser = firebaseAuth.createUserWithEmailAndPassword(email,password) .await().user ?: throw IllegalStateException("Sign up error - user is null") suspend fun signIn(email: String, password: String): FirebaseUser = firebaseAuth.signInWithEmailAndPassword(email,password) .await().user ?: throw IllegalStateException("Sign in error - user is null") suspend fun signInAsGuest(): FirebaseUser = firebaseAuth.signInAnonymously() .await().user ?: throw IllegalStateException("Sign In Anonymously error - user is null") suspend fun resetPassword(email: String){ firebaseAuth.sendPasswordResetEmail(email).await() } suspend fun signInWithGoogle(idToken: String): FirebaseUser{ android.util.Log.d("FirebaseAuthDataSource", "[Google] Creating credential") val credential = GoogleAuthProvider.getCredential(idToken, null) android.util.Log.d("FirebaseAuthDataSource", "[Google] Credential created: ${credential != null}") android.util.Log.d("FirebaseAuthDataSource", "[Google] Calling signInWithCredential...") val user = firebaseAuth.signInWithCredential(credential) .await().user android.util.Log.d("FirebaseAuthDataSource", "[Google] Result user: ${user?.uid}") return user ?: throw IllegalStateException("Sign in error - user is null") } fun getCurrentUser(): FirebaseUser? = firebaseAuth.currentUser suspend fun signOut() { firebaseAuth.signOut() } }