Skip to content

Commit

Permalink
signupNewUser implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobCube committed Sep 10, 2024
1 parent 482e35b commit f63e1b3
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/main/java/com/google/firebase/auth/FirebaseAuth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,38 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
return source.task
}

fun createUserWithEmailAndPassword(email: String, password: String): Task<AuthResult> {
val source = TaskCompletionSource<AuthResult>()
val body = RequestBody.create(
json,
JsonObject(mapOf("email" to JsonPrimitive(email), "password" to JsonPrimitive(password), "returnSecureToken" to JsonPrimitive(true))).toString()
)
val request = Request.Builder()
.url("https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=" + app.options.apiKey)
.post(body)
.build()
client.newCall(request).enqueue(object : Callback {

override fun onFailure(call: Call, e: IOException) {
source.setException(FirebaseException(e.toString(), e))
}

@Throws(IOException::class)
override fun onResponse(call: Call, response: Response) {
if (!response.isSuccessful) {
source.setException(
createAuthInvalidUserException("signupNewUser", request, response)
)
} else {
val responseBody = response.body()?.use { it.string() } ?: ""
val user = FirebaseUserImpl(app, jsonParser.parseToJsonElement(responseBody).jsonObject)
refreshToken(user, source) { AuthResult { it } }
}
}
})
return source.task
}

fun signInWithEmailAndPassword(email: String, password: String): Task<AuthResult> {
val source = TaskCompletionSource<AuthResult>()
val body = RequestBody.create(
Expand Down Expand Up @@ -425,7 +457,6 @@ class FirebaseAuth constructor(val app: FirebaseApp) : InternalAuthProvider {
}

fun sendPasswordResetEmail(email: String, settings: ActionCodeSettings?): Task<Unit> = TODO()
fun createUserWithEmailAndPassword(email: String, password: String): Task<AuthResult> = TODO()
fun signInWithCredential(authCredential: AuthCredential): Task<AuthResult> = TODO()
fun checkActionCode(code: String): Task<ActionCodeResult> = TODO()
fun confirmPasswordReset(code: String, newPassword: String): Task<Unit> = TODO()
Expand Down

0 comments on commit f63e1b3

Please sign in to comment.