diff --git a/src/app/(student)/layout.tsx b/src/app/(student)/layout.tsx index 69e42d5..c570fce 100644 --- a/src/app/(student)/layout.tsx +++ b/src/app/(student)/layout.tsx @@ -11,12 +11,16 @@ export default async function StudentLayout({ children }: { children: React.Reac const session = await auth.api.getSession({ headers: await headers() }); if (!session) redirect("/login"); - // Force password change for auto-provisioned buyers (temp password) + const isImpersonating = !!(session.session as { impersonatedBy?: string }).impersonatedBy; + + // Force password change for auto-provisioned buyers (temp password). + // Skip while an admin is impersonating — they only view the client's cabinet; + // the client sets their own password on a real first login. const dbUser = await prisma.user.findUnique({ where: { id: session.user.id }, select: { mustChangePassword: true }, }); - if (dbUser?.mustChangePassword) redirect("/change-password"); + if (dbUser?.mustChangePassword && !isImpersonating) redirect("/change-password"); // Maintenance mode: non-admin users see the maintenance page if (session.user.role !== "admin") { @@ -35,8 +39,6 @@ export default async function StudentLayout({ children }: { children: React.Reac getSetting("orgRequisites"), ]); - const isImpersonating = !!(session.session as { impersonatedBy?: string }).impersonatedBy; - return (
{isImpersonating && } diff --git a/src/app/change-password/page.tsx b/src/app/change-password/page.tsx index 86357bb..0aaed00 100644 --- a/src/app/change-password/page.tsx +++ b/src/app/change-password/page.tsx @@ -2,24 +2,30 @@ import { headers } from "next/headers"; import { auth } from "@/lib/auth"; import { redirect } from "next/navigation"; import { ForceChangeForm } from "./force-change-form"; +import { StopImpersonateBanner } from "@/components/admin/stop-impersonate-banner"; export default async function ChangePasswordPage() { const session = await auth.api.getSession({ headers: await headers() }); if (!session) redirect("/login"); + const isImpersonating = !!(session.session as { impersonatedBy?: string }).impersonatedBy; + return (
-
-

- Задайте свой пароль -

-

- Вы вошли с временным паролем. Перед началом работы задайте постоянный — это займёт минуту. -

- + {isImpersonating && } +
+
+

+ Задайте свой пароль +

+

+ Вы вошли с временным паролем. Перед началом работы задайте постоянный — это займёт минуту. +

+ +
);