Firebase APIs outside of an Injection context
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- angular, firebase, typescript
- Lĩnh vực
- authentication, database
Hướng nghiên cứu
Bắt đầu với các Firebase provider trong Appconfig.ts, sau đó kiểm tra Auth subscription và các lệnh gọi Firebase trong Service, cùng với signup flow trong Component. Tái hiện hành vi reload và signup, đồng thời kiểm tra thời điểm cảnh báo injection context xuất hiện. Hoàn thành khi cảnh báo và độ trễ xác thực được giải quyết mà không làm hỏng signup hoặc các thao tác ghi vào Firestore.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I keep getting error about,
Calling Firebase APIs outside of an Injection context may destabilize your application leading to subtle change-detection and hydration bugs.
I did properly set up the angular firebase integration although signIn, logIn working properly, but this error won't resolve and it makes the authentication delay at each reload.
Appconfig.ts -
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: ""
}
export const appConfig: ApplicationConfig = {
providers:
[
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes),
provideHttpClient(),
provideFirebaseApp(() => initializeApp(firebaseConfig)),
provideAuth(() => getAuth()),
provideFirestore(() => getFirestore())
]
};
Service:
auth: Auth = inject(Auth)
fireStore: Firestore = inject(Firestore)
ngZone = inject(NgZone)
userSubject: BehaviorSubject = new BehaviorSubject(null)
private authSubscription;
constructor() {
this.authSubscription = this.auth.onAuthStateChanged(user => {
this.userSubject.next(user)
})
}
signUp(fullName: string, email: string, password: string, username: string, phone: string = '', address: string = '', pincode: string): Observable {
return this.ngZone.run(() => {
const promise = createUserWithEmailAndPassword(this.auth, email, password)
.then(response => {
const userCredentials = response.user;
if (userCredentials) {
return sendEmailVerification(userCredentials)
.then(() => {
// Update profile with username
return updateProfile(userCredentials, { displayName: username })
.then(() => {
// Save user details in Firestore
return this.saveUserDetails(response.user.uid, fullName, address, phone, pincode);
})
.catch(error => {
console.error("Error updating profile:", error);
throw new Error('Profile update failed');
});
})
.catch(error => {
console.error("Error sending email verification:", error);
throw new Error('Email verification failed');
});
} else {
throw new Error('User credentials not found');
}
})
.catch(error => {
console.error("Error during signup:", error);
throw error; // Propagate the error
});
return from(promise).pipe(
map(() => { }),
catchError(error => {
console.error("Error in signup:", error);
return throwError(() => new Error(error.message)); // Return an error observable
})
);
})
}
saveUserDetails(uid: string, fullName: string, address: string, phone: string, pincode: string): Promise {
const userRef = doc(this.fireStore, 'users', uid)
return setDoc(userRef, {
fullName: fullName,
address: address,
phone: phone,
pincode: pincode
}).then(() => {
console.log("User details saved in Firestore.");
}).catch((error) => {
console.error("Error saving user details in Firestore:", error);
throw error; // rethrow to propagate error in the stream
});
}
Component:
onSubmit() {
const rawForm = this.signUpForm.getRawValue();
this.loader.showLoader()
this.authService.signUp(rawForm.name,rawForm.email, rawForm.password, rawForm.username, rawForm.phone, rawForm.address, rawForm.pincode).subscribe((next) => {
this.router.navigateByUrl('/email-ver')
this.loader.hideLoader()
}, err => {
console.log('Some error occurred during signup', err);
this.loader.hideLoader()
})
}
- Ngôn ngữ chính
- TypeScript
- Star
- 7.8k
- Fork
- 2.2k
- Merge trung bình
- 3 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 5
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của angular/angularfire
-
comp: build/pipeline type: bug version: current (v17+)
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
angular/angularfire#3766 ·
-
comp: schematics type: bug version: current (v17+)
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
angular/angularfire#3768 ·
-
comp: docs type: chore version: current (v17+)
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
angular/angularfire#3764 ·
-
comp: firestore comp: ssr priority: P0 (critical) type: feature version: current (v17+)
angular/angularfire#3757 · 1 người được giao ·
-
Six `firebase` entry points have no `@angular/fire` equivalent, so their exports are unreachable Đang mởcomp: core type: feature
angular/angularfire#3755 · 1 người được giao ·
Tất cả issue của angular/angularfire
Issue tương tự
-
[Bug]: Discord Activity titles with emoji are rejected as over 80 characters when they are not Đang mởclawsweeper:linked-pr-open clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:message-loss issue-rating: 🦞 diamond lobster maturity:stable P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Eynzof/Hermes-CN-Desktop#616 ·
-
ZCode 3.14.3 に対応する Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
supermomonga/zcode-acp#24 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
growthbook/growthbook#7100 ·
-
triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100