Initialize Firebase
Using Environment Variables
https://console.firebase.google.com/u/0/project/<your-project-name>/settings/generalhttps://console.cloud.google.com/apis/credentials?authuser=0&project=<your-project-name>set FIREBASE_API_KEY=your_api_key
set FIREBASE_PROJECT_ID=your_project_id import 'package:firebase_dart_admin_auth_sdk/firebase_dart_admin_auth_sdk.dart';
void main() async {
//Pass the enviroment variables into the function below, I.E API key and project ID
FirebaseApp.initializeAppWithEnvironmentVariables(
apiKey: FIREBASE_API_KEY,
projectId: FIREBASE_PROJECT_ID,
);
// Get Firebase auth instance for this project
FirebaseApp.instance.getAuth();
// Example: Sign in with email and password
try {
final user = await FirebaseApp.firebaseAuth
?.createUserWithEmailAndPassword('[email protected]', 'password');
final await userCredential = await FirebaseApp.firebaseAuth
?.signInWithEmailAndPassword('[email protected]', 'password');
print('Signed in as ${userCredential?.user.email}');
} catch (e) {
print('Sign-in error: $e');
}
}
Using Service Account Methods
Using service account with keys
Using service account without key impersonation
Last updated