firebase - 如何使用firebase auth限制对next.js中页面的访问?
问题描述
我正在开发一个使用 firebase 的 next.js 应用程序。我需要使用 firebase auth 包来限制对页面的访问。with-firebase-authentication 示例不显示多个页面的身份验证。
import React from 'react';
import Router from 'next/router';
import { firebase } from '../../firebase';
import * as routes from '../../constants/routes';
const withAuthorization = (needsAuthorization) => (Component) => {
class WithAuthorization extends React.Component {
componentDidMount() {
firebase.auth.onAuthStateChanged(authUser => {
if (!authUser && needsAuthorization) {
Router.push(routes.SIGN_IN)
}
});
}
render() {
return (
<Component { ...this.props } />
);
}
}
return WithAuthorization;
}
export default withAuthorization;
解决方案
也在努力集成 firebase 身份验证,最终使用了 nextjs 的 with-iron-session 示例中详述的方法:https ://github.com/hajola/with-firebase-auth-iron-session
推荐阅读
- git - 是否有一个 gitkraken 功能可以显示背后有多少提交?前面一个分支与另一个分支进行比较?
- laravel - “错误”:“invalid_grant” Laravel 7 护照
- flutter - 模型类中的属性更改后更新 UI
- amazon-web-services - 数据管道(DynamoDB 到 S3) - 如何格式化 S3 文件?
- c# - 使用嵌套对象键生成 JSON
- excel - 在 Excel 中的 2 个团队之间平均分配球员
- azure - 无法使用“客户”托管加密密钥选项在 Azure 认知搜索中创建索引/同义词映射
- xml - 使用 xslt1.0 基于输入 xml 动态构建节点集
- python - 尝试从 TWS API 请求基础数据
- python - Python添加带有条件的数据框col