Authentication
Firebase Authentication for iOS via the FirebaseIOS.auth autoload.
Official Firebase docs: Firebase Authentication · Get started (iOS)
Signals
-
auth_success(current_user_data: Dictionary)Emitted when a user successfully signs in. -
auth_failure(error_message: String)Emitted when an authentication operation fails. -
link_with_google_success(current_user_data: Dictionary)Emitted when an anonymous user is successfully linked to a Google account. -
link_with_google_failure(error_message: String)Emitted when linking an anonymous user to a Google account fails. -
link_with_apple_success(current_user_data: Dictionary)Emitted when an anonymous user is successfully linked to an Apple account. -
link_with_apple_failure(error_message: String)Emitted when linking an anonymous user to an Apple account fails. -
sign_out_success(success: bool)Emitted after a sign-out operation. -
user_deleted(success: bool)Emitted after an attempt to delete the current user. -
create_user_success(current_user_data: Dictionary)Emitted when a new email/password user is successfully created. -
create_user_failure(error_message: String)Emitted when creating a user fails. -
password_reset_success(success: bool)Emitted when a password reset email is sent successfully. -
password_reset_failure(error_message: String)Emitted when sending a password reset email fails. -
auth_state_changed(signed_in: bool, current_user_data: Dictionary)Emitted when the authentication state changes (user signs in or out). -
id_token_result(token: String)Emitted with the user’s ID token. -
id_token_error(error_message: String)Emitted when retrieving the ID token fails. -
profile_updated(success: bool)Emitted when a profile update succeeds. -
profile_update_failure(error_message: String)Emitted when a profile update fails.
Methods
sign_in_anonymously()
Signs in anonymously. If a session already exists, returns data for the current user without creating a new one.
Emits: auth_success or auth_failure.
FirebaseIOS.auth.sign_in_anonymously()
sign_in_with_google()
Signs in using Google OAuth via GIDSignIn. Requires a physical iOS device (arm64).
Emits: auth_success or auth_failure.
FirebaseIOS.auth.sign_in_with_google()
sign_in_with_apple()
Signs in using Apple Sign-In via ASAuthorization.
Emits: auth_success or auth_failure.
FirebaseIOS.auth.sign_in_with_apple()
link_anonymous_with_google()
Links the currently signed-in anonymous user to a Google account. The anonymous UID and data are preserved.
Emits: link_with_google_success or link_with_google_failure.
FirebaseIOS.auth.link_anonymous_with_google()
link_with_apple()
Links the currently signed-in anonymous user to an Apple account. The anonymous UID and data are preserved.
Emits: link_with_apple_success or link_with_apple_failure.
FirebaseIOS.auth.link_with_apple()
sign_out()
Signs out from Firebase and Google.
Emits: sign_out_success. Also emits auth_failure on failure.
FirebaseIOS.auth.sign_out()
delete_current_user()
Deletes the currently signed-in Firebase user.
Emits: user_deleted. Also emits auth_failure on failure.
FirebaseIOS.auth.delete_current_user()
is_signed_in() -> bool
Returns true if a user session currently exists, otherwise false.
FirebaseIOS.auth.is_signed_in()
get_current_user_data() -> Dictionary
Returns a dictionary with the current user’s data, or an empty dictionary if no user is signed in.
uid— User IDemail— Email address (empty string if not available)displayName— Display name (empty string if not set)photoURL— Profile photo URL (empty string if not set)isAnonymous— Whether the user is anonymousproviderData— Array of linked providers, each withproviderId,uid,email,displayName,photoURLphoneNumber— Phone number (empty string if not set)isEmailVerified— Whether the user’s email has been verifiedmetadata— Dictionary withcreationDateandlastSignInDateas ISO 8601 strings
var user = FirebaseIOS.auth.get_current_user_data()
use_emulator(host: String, port: int)
Connects to the Firebase Auth Emulator. Call this before any auth operations.
FirebaseIOS.auth.use_emulator("localhost", 9099)
create_user_with_email(email: String, password: String)
Creates a new user with email and password.
Emits: create_user_success or create_user_failure.
FirebaseIOS.auth.create_user_with_email("user@example.com", "password123")
sign_in_with_email(email: String, password: String)
Signs in with email and password.
Emits: auth_success or auth_failure.
FirebaseIOS.auth.sign_in_with_email("user@example.com", "password123")
send_password_reset_email(email: String)
Sends a password reset email.
Emits: password_reset_success or password_reset_failure.
FirebaseIOS.auth.send_password_reset_email("user@example.com")
add_auth_state_listener()
Starts listening for auth state changes.
Emits: auth_state_changed whenever the user signs in or out.
FirebaseIOS.auth.add_auth_state_listener()
remove_auth_state_listener()
Stops listening for auth state changes.
FirebaseIOS.auth.remove_auth_state_listener()
get_id_token(force_refresh: bool = false)
Retrieves the current user’s Firebase ID token.
Emits: id_token_result or id_token_error.
FirebaseIOS.auth.get_id_token(false)
update_profile(display_name: String, photo_url: String = “”)
Updates the current user’s display name and/or photo URL. Only non-empty values are applied.
Emits: profile_updated or profile_update_failure.
FirebaseIOS.auth.update_profile("Alice", "")
update_password(new_password: String)
Updates the current user’s password. May require recent reauthentication.
Emits: profile_updated or auth_failure.
FirebaseIOS.auth.update_password("newSecurePassword")
send_email_verification()
Sends an email verification to the current user.
Emits: profile_updated or auth_failure.
FirebaseIOS.auth.send_email_verification()
reload_user()
Reloads the current user’s data from the server.
Emits: auth_success with refreshed data, or auth_failure.
FirebaseIOS.auth.reload_user()
unlink_provider(provider_id: String)
Unlinks a provider from the current user.
Emits: auth_success or auth_failure.
FirebaseIOS.auth.unlink_provider("google.com")
reauthenticate_with_email(email: String, password: String)
Reauthenticates the current user with email credentials. Required before sensitive operations.
Emits: auth_success or auth_failure.
FirebaseIOS.auth.reauthenticate_with_email("user@example.com", "password123")
Known Limitations
- Google Sign-In requires a physical iOS device (arm64). The iOS Simulator is not supported.