小编wal*_*per的帖子

使用 Firebase 身份验证保护 NextJS 中的路由

我要保护的路线: /account

如果用户未通过身份验证,则重定向到 /signIn

拥有 SSR NextJS 项目并使用 Firebase 身份验证,我如何才能实现经过生产实战测试的正确保护路由?

NextJS 文档中提供的示例现在无法正常工作: with-firebase-auth

所以我提交了一个问题: with-firebase-auth-example-not-working

再加上我是 NextJs 的新手,不幸的是,我从未使用过 JWT :( 或任何类型的后端保护路由 cookie/JWT/sessions 实现......直到现在我想要/需要它。

我尝试过什么样的解决方法,嗯,像这样:

import Account from "./Account.js";
import Loading from "./Loading.js";
import { useRequireAuth } from "./use-require-auth.js";

function Account(props) {
  const auth = useRequireAuth();

  // If auth is null (still fetching data) 
  // or false (logged out, above hook will redirect)
  // then show loading indicator.
  if (!auth) {
    return <Loading />;
  }

  return (
    <Account auth={auth} />
  ); …
Run Code Online (Sandbox Code Playgroud)

firebase-authentication next.js

8
推荐指数
1
解决办法
1421
查看次数

标签 统计

firebase-authentication ×1

next.js ×1