angular - 即使在登录 Angular 之后,直接点击 url 也会再次进入登录页面
问题描述
Firebase 身份验证集成在 Angular 应用程序中。即使在登录到应用程序后,直接在新选项卡或浏览器的同一选项卡上点击 url 或路由,chrome,例如http://localhost:4200/landing 会再次进入登录页面。
如果已经登录,有没有办法不跳过登录页面。
重现步骤
- ng serve在 Angular CLI 项目中将我带到http://localhost:4200/login
- 登录后需要http://localhost:4200/landing
- 打开一个新选项卡或在现有选项卡类型中,http://localhost:4200/landing回车
解决方案
我认为需要进行以下更改。
constructor(private _firebaseAuth: AngularFireAuth, private router: Router) {
this.user = _firebaseAuth.authState;
this.user.subscribe(
(user) => {
if (user) {
this.userDetails = user;
// Set the UserId
localStorage.setItem('userId', user.uid);
} else {
this.userDetails = null;
}
}
);
}
isLoggedIn() {
if (this.userDetails == null) {
// Check the UserId
if (localStorage.getItem('userId')) {
return true;
}
return false;
} else {
return true;
}
}
推荐阅读
- excel - PMT 错误:参数数量错误或属性分配无效
- java - 如何使用 For 循环从 DB 中拆分不同 LiearLayout 中的名称
- go - 导入由 cython 生成的 c-shared 库与 cgo 一起使用
- apache-kafka - 如何测试使用 Avro 和 Confluent Schema Registry 的 Spring Cloud Stream Kafka Streams 应用程序?
- hyperledger - 单个事务被提交,批次中的多个事务保持在 PENDING 状态
- python - 如何在一列中查找具有相同值但在另一列中具有不同值的记录
- scala - 如何使用正确的名称在 scala 中对表进行分区
- linux - linux find 命令:从结果中排除路径
- python - 如何根据多个相同的第一列元素对二维列表进行切片
- python - 使用 BeautifulSoup 从 Div 标签声明中提取内容