ข้ามไปยังเนื้อหา

หน้าตัวอย่าง

ไม่มีสิทธิ์ 403

ใช้เมื่อผู้ใช้เข้าสู่ระบบแล้ว แต่บัญชีของเขาไม่มีสิทธิ์ที่หน้านั้นต้องใช้ หน้าเรียก forbidden() ของ Next.js แล้ว forbidden.tsx ที่ใกล้ที่สุดแสดงผล ถ้ายังไม่เข้าสู่ระบบ ให้พาไปหน้าเข้าสู่ระบบแทน ไม่ใช่ 403 ถ้าสิ่งที่ขอไม่มีอยู่ ใช้หน้าไม่พบหน้า 404

คอมโพเนนต์ที่ใช้

import { StatusPage, Button, AppShell } from "@bsru/ui";

กฎของหน้านี้

ถ้อยคำ

  • บอกว่าทำอะไรไม่ได้ และต้องมีสิทธิ์อะไร โดยใช้ชื่อที่ผู้ใช้รู้จัก เช่น ผู้อนุมัติของหน่วยงาน ไม่ใช่ชื่อสิทธิ์ในระบบ
  • บอกว่าติดต่อใครเพื่อขอสิทธิ์ ระบบยังไม่มีการขอสิทธิ์ในหน้าจอ

ปุ่มและทางไปต่อ

  • ปุ่มหลักหนึ่งปุ่ม: กลับหน้าแรก
  • เมื่อผู้ใช้อาจเข้าผิดบัญชี เช่น ผู้ใช้ ERP เข้าคอนโซล ให้ปุ่มเข้าสู่ระบบด้วยบัญชีอื่น และลิงก์ไประบบที่ถูกต้อง

ห้ามแสดง

  • ชื่อสิทธิ์ภายใน บทบาท หรือกฎที่ตรวจไม่ผ่าน
  • ข้อมูลใดของหน้าที่ถูกปฏิเสธ รวมถึงชื่อหรือจำนวนของระเบียน

ในแอป

  • ตรวจสิทธิ์ก่อนโหลดข้อมูล และตอบด้วยสถานะ HTTP 403 ซึ่ง forbidden() ทำให้ สิทธิ์จริงตรวจที่ API หลักเสมอ หน้านี้เพียงบอกผู้ใช้
  • ในโครงแอปส่ง fill={false} นอกโครงแอปใช้แบบเต็มหน้าจอ พร้อม brand และ notice ในระบบจำลอง

ตัวอย่างทั้งหน้า

แต่ละตัวอย่างเป็นหน้าเต็ม แสดงในกรอบจอคอมพิวเตอร์ เลือกโทรศัพท์หรือแท็บเล็ตที่แถบบนเพื่อดูบนจอนั้น ข้อมูลทั้งหมดเป็นข้อมูลสมมติ

ERP: ไม่มีสิทธิ์ ในโครงแอป

ผู้ใช้ ERP เปิดหน้าอนุมัติโดยไม่ได้เป็นผู้อนุมัติ forbidden.tsx แสดงใน AppShell บอกสิทธิ์ที่ต้องมีและติดต่อใคร

จอคอมพิวเตอร์ 1280 × 800 px
// next.config.ts: forbidden() and forbidden.tsx need authInterrupts.
const nextConfig: NextConfig = { experimental: { authInterrupts: true } };

// app/(erp)/vouchers/approve/page.tsx: the page checks the right before it loads anything.
import { forbidden } from "next/navigation";

const user = await requireUser();
if (!user.can("voucher.approve")) forbidden();

// app/(erp)/forbidden.tsx: shown inside the ERP's AppShell.
import { Button, StatusPage } from "@bsru/ui";
import { House } from "lucide-react";
import { getTranslations } from "next-intl/server";

export default async function Forbidden() {
  const t = await getTranslations();
  return (
    <StatusPage
      kind="forbidden"
      fill={false}
      title={t("vouchers.forbidden.title")}
      description={t("vouchers.forbidden.body")}
      actions={<Button tone="primary" icon={House} label={t("status.home")} href="/" />}
    />
  );
}

คอนโซล: เข้าด้วยบัญชีผู้ใช้ ERP

คอนโซลเปิดได้เฉพาะผู้ดูแลระบบ หน้าเต็มจอนี้ให้เข้าสู่ระบบด้วยบัญชีอื่น หรือไปที่ BSRU ERP

จอคอมพิวเตอร์ 1280 × 800 px
// app/forbidden.tsx: an ERP user who signs in to the console, before the console's frame.
import { Button, StatusPage } from "@bsru/ui";
import { ExternalLink, LogIn } from "lucide-react";
import { getTranslations } from "next-intl/server";
import { erpUrl, isDemo } from "@/server/env";

export default async function Forbidden() {
  const t = await getTranslations();
  return (
    <StatusPage
      kind="forbidden"
      brand={{ name: t("brand.console"), caption: t("brand.university"), logo: "/bsru-logo.png", alt: t("brand.seal") }}
      notice={isDemo() ? t("shell.demo") : undefined}
      title={t("status.wrongUserType.title")}
      description={t("status.wrongUserType.body")}
      actions={
        <>
          <Button tone="primary" icon={LogIn} label={t("auth.switchAccount")} href="/auth/login?prompt=login" />
          <Button icon={ExternalLink} label={t("status.openErp")} href={erpUrl()} />
        </>
      }
    />
  );
}