我要保护的路线: /account
如果用户未通过身份验证,则重定向到 /signIn
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)