inehemiasm/AiAssistant / .agents/skills/firebase-auth-basics
firebase-auth-basics
VerifiedGuide for setting up and using Firebase Authentication. Use this skill when the user's app requires user sign-in, user management, or secure data access using auth rules.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 3.6 KB |
| references/client_sdk_android.md | markdown | 4.2 KB |
| references/client_sdk_web.md | markdown | 6.9 KB |
| references/flutter_setup.md | markdown | 4.5 KB |
| references/ios_setup.md | markdown | 2.4 KB |
| references/security_rules.md | markdown | 1.3 KB |
references/ios_setup.md
View on GitHub# Firebase Auth iOS Setup Guide
# ⛔️ CRITICAL RULE: NO INLINE INITIALIZATION ⛔️
NEVER write `let auth = Auth.auth()` as an inline class or struct property if there is ANY chance the object is instantiated before `FirebaseApp.configure()` executes in the app root.
- **FATAL CRASH:** `@Observable class AuthManager { let auth = Auth.auth() }` initialized as a `@State` in the App root.
- **SAFE PATTERN:** Initialize `Auth.auth()` lazily (`lazy var auth = Auth.auth()`) OR explicitly initialize the manager *after* `FirebaseApp.configure()` finishes.
## 1. Import and Initialize
Ensure you have installed the `FirebaseAuth` SDK. Use the `xcode-project-setup` skill to automate adding the SPM dependency to the Xcode project.
> **Note:** Ensure `FirebaseApp.configure()` has been executed in your app's entry point before calling any `Auth.auth()` methods, otherwise your app will crash. Do not initialize Auth objects in SwiftUI `@State` properties at the App root level.
```swift
import FirebaseAuth
```
## 2. Authentication State
To listen for authentication state changes (recommended way to check if a user is signed in):
```swift
var handle: AuthStateDidChangeListenerHandle?
handle = Auth.auth().addStateDidChangeListener { auth, user in
if let user = user {
print("User is signed in with uid: \(user.uid)")
} else {
print("User is signed out")
}
}
// To remove the listener when no longer needed:
if let handle = handle {
Auth.auth().removeStateDidChangeListener(handle)
}
```
## 3. Email and Password Authentication (Modern Concurrency)
Modern Swift projects should prioritize `async/await` for authentication calls to avoid nested completion handlers and improve readability.
### Sign Up
```swift
do {
let authResult = try await Auth.auth().createUser(withEmail: "user@example.com", password: "password")
print("User created successfully with uid: \(authResult.user.uid)")
} catch {
print("Error creating user: \(error.localizedDescription)")
}
```
### Sign In
```swift
do {
let authResult = try await Auth.auth().signIn(withEmail: "user@example.com", password: "password")
print("User signed in successfully with uid: \(authResult.user.uid)")
} catch {
print("Error signing in: \(error.localizedDescription)")
}
```
## 4. Sign Out
```swift
do {
try Auth.auth().signOut()
print("Successfully signed out")
} catch let signOutError as NSError {
print("Error signing out: \(signOutError)")
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |