mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-02-13 20:35:43 +01:00
fix: resolve Prettier markdown code block parsing errors
- Fix syntax errors in skills markdown files (.github/skills, .opencode/skills) - Change typescript to tsx for code blocks with JSX - Replace ellipsis (...) in array examples with valid syntax - Separate CSS from TypeScript into distinct code blocks - Convert JavaScript object examples to valid JSON in docs - Fix enum definitions with proper comma separation
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { hash } from "bcryptjs";
|
||||
import { type NextRequest, NextResponse } from "next/server";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { platformAuthOptions } from "../../../../../../lib/platform-auth";
|
||||
import { prisma } from "../../../../../../lib/prisma";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
import {
|
||||
getAuthenticatedPlatformUser,
|
||||
hasPlatformAccess,
|
||||
} from "@/lib/auth/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
// POST /api/platform/companies/[id]/users - Invite user to company
|
||||
export async function POST(
|
||||
@@ -12,11 +11,11 @@ export async function POST(
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(platformAuthOptions);
|
||||
const { user: platformUser } = await getAuthenticatedPlatformUser();
|
||||
|
||||
if (
|
||||
!session?.user?.isPlatformUser ||
|
||||
session.user.platformRole === "SUPPORT"
|
||||
!platformUser ||
|
||||
!hasPlatformAccess(platformUser.role, "PLATFORM_ADMIN")
|
||||
) {
|
||||
return NextResponse.json(
|
||||
{ error: "Admin access required" },
|
||||
@@ -53,34 +52,26 @@ export async function POST(
|
||||
);
|
||||
}
|
||||
|
||||
// Check if user already exists in this company
|
||||
const existingUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
email,
|
||||
companyId,
|
||||
},
|
||||
// Check if user already exists
|
||||
const existingUser = await prisma.user.findUnique({
|
||||
where: { email },
|
||||
});
|
||||
|
||||
if (existingUser) {
|
||||
return NextResponse.json(
|
||||
{ error: "User already exists in this company" },
|
||||
{ error: "User with this email already exists" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Generate a temporary password (in a real app, you'd send an invitation email)
|
||||
const tempPassword = `temp${Math.random().toString(36).slice(-8)}`;
|
||||
const hashedPassword = await hash(tempPassword, 10);
|
||||
|
||||
// Create the user
|
||||
// Create the user placeholder (they'll complete signup via Neon Auth)
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
name,
|
||||
email,
|
||||
password: hashedPassword,
|
||||
role,
|
||||
companyId,
|
||||
invitedBy: session.user.email,
|
||||
invitedBy: platformUser.email,
|
||||
invitedAt: new Date(),
|
||||
},
|
||||
select: {
|
||||
@@ -94,13 +85,12 @@ export async function POST(
|
||||
},
|
||||
});
|
||||
|
||||
// In a real application, you would send an email with login credentials
|
||||
// For now, we'll return the temporary password
|
||||
// TODO: Send invitation email with sign-up link
|
||||
return NextResponse.json({
|
||||
user,
|
||||
tempPassword, // Remove this in production and send via email
|
||||
signupUrl: "/auth/sign-up",
|
||||
message:
|
||||
"User invited successfully. In production, credentials would be sent via email.",
|
||||
"User invited. They should sign up at /auth/sign-up with this email.",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Platform user invitation error:", error);
|
||||
@@ -117,9 +107,9 @@ export async function GET(
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(platformAuthOptions);
|
||||
const { user } = await getAuthenticatedPlatformUser();
|
||||
|
||||
if (!session?.user?.isPlatformUser) {
|
||||
if (!user) {
|
||||
return NextResponse.json(
|
||||
{ error: "Platform access required" },
|
||||
{ status: 401 }
|
||||
|
||||
Reference in New Issue
Block a user