【发布时间】:2021-11-14 18:10:16
【问题描述】:
我正在尝试使用 TypeScript 跟踪下一个身份验证 documentation。使用以下代码和文档中_app.tsx 中的一些代码,我可以保护页面:
AdminDashboard.auth = {
role: "admin",
loading: <AdminLoadingSkeleton />,
unauthorized: "/login-with-different-user", // redirect to this url
}
使用 TypeScript 实现这一点的正确方法是什么?
我找到了一个可行的解决方案,但我不确定这是否是正确的方法:
export type NextPageWithAuth = NextPage & {
auth: boolean,
role: string
}
type NextPageAuthProps = {
Component: NextPageWithAuth,
pageProps: any
}
AppProps 类型比我自己的 NextPageAuthProps 复杂得多。
【问题讨论】:
标签: javascript reactjs typescript next.js