|
14 | 14 |
|
15 | 15 | package com.firebase.ui.auth.compose
|
16 | 16 |
|
| 17 | +import com.firebase.ui.auth.compose.AuthException.Companion.from |
17 | 18 | import com.google.firebase.FirebaseException
|
18 | 19 | import com.google.firebase.auth.FirebaseAuthException
|
19 | 20 | import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException
|
@@ -204,6 +205,38 @@ abstract class AuthException(
|
204 | 205 | cause: Throwable? = null
|
205 | 206 | ) : AuthException(message, cause)
|
206 | 207 |
|
| 208 | + class InvalidEmailLinkException( |
| 209 | + cause: Throwable? = null |
| 210 | + ) : AuthException("You are are attempting to sign in with an invalid email link", cause) |
| 211 | + |
| 212 | + class EmailLinkWrongDeviceException( |
| 213 | + cause: Throwable? = null |
| 214 | + ) : AuthException("You must open the email link on the same device.", cause) |
| 215 | + |
| 216 | + class EmailLinkCrossDeviceLinkingException( |
| 217 | + cause: Throwable? = null |
| 218 | + ) : AuthException( |
| 219 | + "You must determine if you want to continue linking or " + |
| 220 | + "complete the sign in", cause |
| 221 | + ) |
| 222 | + |
| 223 | + class EmailLinkPromptForEmailException( |
| 224 | + cause: Throwable? = null |
| 225 | + ) : AuthException("Please enter your email to continue signing in", cause) |
| 226 | + |
| 227 | + class EmailLinkDifferentAnonymousUserException( |
| 228 | + cause: Throwable? = null |
| 229 | + ) : AuthException( |
| 230 | + "The session associated with this sign-in request has either expired or " + |
| 231 | + "was cleared", cause |
| 232 | + ) |
| 233 | + |
| 234 | + class EmailMismatchException( |
| 235 | + cause: Throwable? = null |
| 236 | + ) : AuthException( |
| 237 | + "You are are attempting to sign in a different email than previously " + |
| 238 | + "provided", cause) |
| 239 | + |
207 | 240 | companion object {
|
208 | 241 | /**
|
209 | 242 | * Creates an appropriate [AuthException] instance from a Firebase authentication exception.
|
@@ -244,86 +277,111 @@ abstract class AuthException(
|
244 | 277 | cause = firebaseException
|
245 | 278 | )
|
246 | 279 | }
|
| 280 | + |
247 | 281 | is FirebaseAuthInvalidUserException -> {
|
248 | 282 | when (firebaseException.errorCode) {
|
249 | 283 | "ERROR_USER_NOT_FOUND" -> UserNotFoundException(
|
250 | 284 | message = firebaseException.message ?: "User not found",
|
251 | 285 | cause = firebaseException
|
252 | 286 | )
|
| 287 | + |
253 | 288 | "ERROR_USER_DISABLED" -> InvalidCredentialsException(
|
254 | 289 | message = firebaseException.message ?: "User account has been disabled",
|
255 | 290 | cause = firebaseException
|
256 | 291 | )
|
| 292 | + |
257 | 293 | else -> UserNotFoundException(
|
258 | 294 | message = firebaseException.message ?: "User account error",
|
259 | 295 | cause = firebaseException
|
260 | 296 | )
|
261 | 297 | }
|
262 | 298 | }
|
| 299 | + |
263 | 300 | is FirebaseAuthWeakPasswordException -> {
|
264 | 301 | WeakPasswordException(
|
265 | 302 | message = firebaseException.message ?: "Password is too weak",
|
266 | 303 | cause = firebaseException,
|
267 | 304 | reason = firebaseException.reason
|
268 | 305 | )
|
269 | 306 | }
|
| 307 | + |
270 | 308 | is FirebaseAuthUserCollisionException -> {
|
271 | 309 | when (firebaseException.errorCode) {
|
272 | 310 | "ERROR_EMAIL_ALREADY_IN_USE" -> EmailAlreadyInUseException(
|
273 |
| - message = firebaseException.message ?: "Email address is already in use", |
| 311 | + message = firebaseException.message |
| 312 | + ?: "Email address is already in use", |
274 | 313 | cause = firebaseException,
|
275 | 314 | email = firebaseException.email
|
276 | 315 | )
|
| 316 | + |
277 | 317 | "ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL" -> AccountLinkingRequiredException(
|
278 |
| - message = firebaseException.message ?: "Account already exists with different credentials", |
| 318 | + message = firebaseException.message |
| 319 | + ?: "Account already exists with different credentials", |
279 | 320 | cause = firebaseException
|
280 | 321 | )
|
| 322 | + |
281 | 323 | "ERROR_CREDENTIAL_ALREADY_IN_USE" -> AccountLinkingRequiredException(
|
282 |
| - message = firebaseException.message ?: "Credential is already associated with a different user account", |
| 324 | + message = firebaseException.message |
| 325 | + ?: "Credential is already associated with a different user account", |
283 | 326 | cause = firebaseException
|
284 | 327 | )
|
| 328 | + |
285 | 329 | else -> AccountLinkingRequiredException(
|
286 | 330 | message = firebaseException.message ?: "Account collision error",
|
287 | 331 | cause = firebaseException
|
288 | 332 | )
|
289 | 333 | }
|
290 | 334 | }
|
| 335 | + |
291 | 336 | is FirebaseAuthMultiFactorException -> {
|
292 | 337 | MfaRequiredException(
|
293 |
| - message = firebaseException.message ?: "Multi-factor authentication required", |
| 338 | + message = firebaseException.message |
| 339 | + ?: "Multi-factor authentication required", |
294 | 340 | cause = firebaseException
|
295 | 341 | )
|
296 | 342 | }
|
| 343 | + |
297 | 344 | is FirebaseAuthRecentLoginRequiredException -> {
|
298 | 345 | InvalidCredentialsException(
|
299 |
| - message = firebaseException.message ?: "Recent login required for this operation", |
| 346 | + message = firebaseException.message |
| 347 | + ?: "Recent login required for this operation", |
300 | 348 | cause = firebaseException
|
301 | 349 | )
|
302 | 350 | }
|
| 351 | + |
303 | 352 | is FirebaseAuthException -> {
|
304 | 353 | // Handle FirebaseAuthException and check for specific error codes
|
305 | 354 | when (firebaseException.errorCode) {
|
306 | 355 | "ERROR_TOO_MANY_REQUESTS" -> TooManyRequestsException(
|
307 |
| - message = firebaseException.message ?: "Too many requests. Please try again later", |
| 356 | + message = firebaseException.message |
| 357 | + ?: "Too many requests. Please try again later", |
308 | 358 | cause = firebaseException
|
309 | 359 | )
|
| 360 | + |
310 | 361 | else -> UnknownException(
|
311 |
| - message = firebaseException.message ?: "An unknown authentication error occurred", |
| 362 | + message = firebaseException.message |
| 363 | + ?: "An unknown authentication error occurred", |
312 | 364 | cause = firebaseException
|
313 | 365 | )
|
314 | 366 | }
|
315 | 367 | }
|
| 368 | + |
316 | 369 | is FirebaseException -> {
|
317 | 370 | // Handle general Firebase exceptions, which include network errors
|
318 | 371 | NetworkException(
|
319 | 372 | message = firebaseException.message ?: "Network error occurred",
|
320 | 373 | cause = firebaseException
|
321 | 374 | )
|
322 | 375 | }
|
| 376 | + |
323 | 377 | else -> {
|
324 | 378 | // Check for common cancellation patterns
|
325 |
| - if (firebaseException.message?.contains("cancelled", ignoreCase = true) == true || |
326 |
| - firebaseException.message?.contains("canceled", ignoreCase = true) == true) { |
| 379 | + if (firebaseException.message?.contains( |
| 380 | + "cancelled", |
| 381 | + ignoreCase = true |
| 382 | + ) == true || |
| 383 | + firebaseException.message?.contains("canceled", ignoreCase = true) == true |
| 384 | + ) { |
327 | 385 | AuthCancelledException(
|
328 | 386 | message = firebaseException.message ?: "Authentication was cancelled",
|
329 | 387 | cause = firebaseException
|
|
0 commit comments