diff --git a/app/admin/layout.tsx b/app/admin/layout.tsx
index 8b8c839..a6a000a 100644
--- a/app/admin/layout.tsx
+++ b/app/admin/layout.tsx
@@ -1,16 +1,22 @@
import type { ReactNode } from "react";
import { DashboardNav } from "@/components/dashboard/dashboard-nav";
+import { getMember, getSession } from "@/lib/session";
+import { can, canAccessAdminArea } from "@/lib/permissions";
/**
* /admin sits outside the /dashboard segment, so it needs the member-app nav
* of its own. Authorization stays in the page itself, which reads the live
* member record rather than trusting the token's role.
*/
-export default function AdminLayout({ children }: { children: ReactNode }) {
+export default async function AdminLayout({ children }: { children: ReactNode }) {
+ const session = await getSession();
+ const member = session ? await getMember(session.usn) : null;
+
return (
<>
- {/* /admin is only reachable by elevated users (proxy + page guard), all of whom can sign off journey milestones. */}
-
+ {member && (
+
+ )}
{children}
>
);
diff --git a/app/admin/page.tsx b/app/admin/page.tsx
index 907cc5a..5ee4028 100644
--- a/app/admin/page.tsx
+++ b/app/admin/page.tsx
@@ -121,11 +121,11 @@ export default async function AdminPage() {
{canManageMembers && (
<>
- {pending.length > 0 && (
Waiting for review
+ {pending.length === 0 &&
No requests waiting.
}
{pending.map((member) => (
@@ -136,7 +136,6 @@ export default async function AdminPage() {
the student portal, so there is nothing to check by hand.
- )}
@@ -144,7 +143,7 @@ export default async function AdminPage() {
{approved.map((member) => (
-
+
))}
diff --git a/app/api/admin/members/[usn]/route.ts b/app/api/admin/members/[usn]/route.ts
index 0a796ee..2f279e1 100644
--- a/app/api/admin/members/[usn]/route.ts
+++ b/app/api/admin/members/[usn]/route.ts
@@ -11,7 +11,7 @@ export const runtime = "nodejs";
type Params = { params: Promise<{ usn: string }> };
const schema = z.object({
- action: z.enum(["approve", "reject", "set-role"]),
+ action: z.enum(["approve", "reject", "set-role", "reissue"]),
role: z.enum(["member", "mentor", "admin"]).optional(),
});
@@ -62,6 +62,21 @@ export async function PATCH(request: NextRequest, { params }: Params) {
return NextResponse.json({ ok: true, message: `${target.name}'s request was declined.` });
}
+ if (action === "reissue") {
+ if (target.status !== "approved" || !target.email) {
+ return NextResponse.json({ ok: false, message: "Only approved members with an email can be reissued." }, { status: 409 });
+ }
+ const password = generatePassword();
+ // Send first: if the email fails, their current password keeps working.
+ try {
+ await sendCredentialsEmail({ to: target.email, name: target.name, username: target.usn, password });
+ } catch {
+ return NextResponse.json({ ok: false, message: "The email failed to send, so nothing was changed." }, { status: 502 });
+ }
+ await ref.update({ passwordHash: await hashPassword(password), mustChangePassword: true });
+ return NextResponse.json({ ok: true, message: `New credentials emailed to ${target.name}.` });
+ }
+
// approve
if (target.status === "approved") {
return NextResponse.json({ ok: true, message: `${target.name} is already a member.` });
diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx
index b035284..546d22f 100644
--- a/app/dashboard/page.tsx
+++ b/app/dashboard/page.tsx
@@ -12,6 +12,7 @@ import {
Star,
} from "lucide-react";
import { getMember, getSession } from "@/lib/session";
+import { canAccessAdminArea } from "@/lib/permissions";
import { Avatar } from "@/components/ui/avatar";
import { PushToggle } from "@/components/pwa/push-toggle";
import { InstallButton } from "@/components/pwa/install-button";
@@ -28,7 +29,7 @@ export default async function DashboardPage() {
if (!member) redirect("/login");
const firstName = member.name.split(" ")[0];
- const elevated = member.role === "admin" || member.role === "mentor";
+ const elevated = canAccessAdminArea(member);
const title = member.councilPosition ?? ROLE_LABEL[member.role] ?? "Member";
const joinedYear = member.joinedAt ? new Date(member.joinedAt).getFullYear() : null;
diff --git a/components/admin/member-row.tsx b/components/admin/member-row.tsx
index c0ba3bd..a2c3cbd 100644
--- a/components/admin/member-row.tsx
+++ b/components/admin/member-row.tsx
@@ -26,7 +26,8 @@ export function MemberRow({
const [message, setMessage] = useState(null);
const [failed, setFailed] = useState(false);
- async function act(action: "approve" | "reject" | "set-role", role?: string) {
+ async function act(action: "approve" | "reject" | "set-role" | "reissue", role?: string) {
+ if (action === "reissue" && !confirm(`Email ${member.name} a new password? Their current one will stop working.`)) return;
if (action === "reject" && !confirm(`Decline ${member.name}'s request?`)) return;
setPending(true);
@@ -111,6 +112,16 @@ export function MemberRow({
>
)}
+ {member.status === "approved" && !isSelf && (
+
+ )}
+
{member.status === "approved" && !isSelf && canManageRoles && (