[英]Getting error while using firebase.User method to get username of logged in user from firebase angular project
Below are my lines of code, I have an error getting the current username to display on the browser.下面是我的代码行,我在获取当前用户名以显示在浏览器上时出错。
I created a Navbar that has a dropdown list only to be shown to the logged-in user.我创建了一个 Navbar,它有一个下拉列表,只显示给登录用户。 Login also works perfectly but I cannot get the current user name to show in the drop-down menu.登录也能正常工作,但我无法在下拉菜单中显示当前用户名。 I am using google authentication using firebase.我正在使用 firebase 使用谷歌身份验证。
I am getting below error on below line,我在下面的行中遇到错误,
user: firebase.User;
Error:错误:
Namespace '"E:/Workspace/Angular/oshop/node_modules/firebase/app/dist/app/index"' has no exported member 'User'".命名空间“E:/Workspace/Angular/oshop/node_modules/firebase/app/dist/app/index”没有导出成员“User”。
See my code below.请参阅下面的代码。
bs-navbar.component.ts bs-navbar.component.ts
import { AngularFireAuth } from '@angular/fire/compat/auth';
import { AngularFireModule } from '@angular/fire/compat';
import { Component, OnInit } from '@angular/core';
import * as firebase from 'firebase/app';
import { getAuth, onAuthStateChanged } from "firebase/auth";
//const auth = getAuth();
//const user = auth.currentUser;
@Component({
selector: 'bs-navbar',
templateUrl: './bs-navbar.component.html',
styleUrls: ['./bs-navbar.component.css']
})
export class BsNavbarComponent {
user: firebase.User;
constructor(private afAuth: AngularFireAuth) {
afAuth.authState.subscribe(user => this.user = user)
}
logout(){
this.afAuth.signOut().then(() => {
window.alert('Logged out');
})
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.