-
Couldn't load subscription status.
- Fork 7
refactor: abstract 401, 404 routes to radix context #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
| routes: { | ||
| notFound: { view: () => <NotfoundPage redirectURL="/admin/collections" /> }, | ||
| notAuthorized: { view: () => <NotAuthorizedPage redirectURL="/admin/auth/login" /> }, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, แต่ว่า key ของ routes ควรจะเป็น path มากกว่า e.g. /admin/:id เพราะฉะนั้น ถ้าอยากเพิ่ม option ให้ user แก้ 401 / 404 ได้ ให้ทำผ่าน props ของ NextJsServerConfig แทนดีกว่า เช่น
// ฝั่ง user ใช้
const serverConfig = defineNextJsServerConfig(_serverConfig, {
ui: {
notFound: ...
notAuthorized: ...
}
})
// ฝั่งเรา implement pages/root.tsx
return serverConfig.ui.notFound(...)ชื่อ props เปลี่ยนได้นะ เอาที่เห็นว่าสมควร
| const radixRouter = createRouter<RouterData>({ | ||
| routes: { | ||
| notFound: { | ||
| view: () => uiConfig?.notFound || <NotfoundPage redirectURL="/admin/collections" />, | ||
| }, | ||
| notAuthorized: { | ||
| view: () => | ||
| uiConfig?.notAuthorized || <NotAuthorizedPage redirectURL="/admin/auth/login" />, | ||
| }, | ||
| }, | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
เอาอันนี้ออกด้วย ๆ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
เอาออกแล้วตัว 404, 403 จะใช้วิธีไหนในการเรียกใช้นะครับ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ผมเข้าใจว่าเราไปสร้าง config ที่ nextjs wrapper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ใช้แล้วใน pages/root.tsx
if (!result) {
return router.ctx.options.routes!.notFound.view() // TODO: Type safe
}
let user: any = {}
if (result.requiredAuthentication) {
user = await getUser(props.serverFunction)
if (!user) {
return router.ctx.options.routes!.notAuthorized.view() // TODO: Type safe
}
}
No description provided.