feat: complete platform management features and enhance SEO

- Add comprehensive company management interface with editing, suspension
- Implement user invitation system within companies
- Add Add Company modal with form validation
- Create platform auth configuration in separate lib file
- Add comprehensive SEO metadata with OpenGraph and structured data
- Fix auth imports and route exports for Next.js 15 compatibility
- Add toast notifications with RadixUI components
- Update TODO status to reflect 100% completion of platform features
This commit is contained in:
2025-06-28 13:20:48 +02:00
parent fdb1a9c2b1
commit 1972c5e9f7
26 changed files with 1627 additions and 251 deletions

108
lib/platform-auth.ts Normal file
View File

@ -0,0 +1,108 @@
import { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import { prisma } from "./prisma";
import bcrypt from "bcryptjs";
// Define the shape of the JWT token for platform users
declare module "next-auth/jwt" {
interface JWT {
isPlatformUser?: boolean;
platformRole?: string;
}
}
// Define the shape of the session object for platform users
declare module "next-auth" {
interface Session {
user: {
id?: string;
name?: string;
email?: string;
image?: string;
isPlatformUser?: boolean;
platformRole?: string;
companyId?: string;
role?: string;
};
}
interface User {
id: string;
email: string;
name?: string;
isPlatformUser?: boolean;
platformRole?: string;
companyId?: string;
role?: string;
}
}
export const platformAuthOptions: NextAuthOptions = {
providers: [
CredentialsProvider({
name: "Platform Credentials",
credentials: {
email: { label: "Email", type: "text" },
password: { label: "Password", type: "password" },
},
async authorize(credentials) {
if (!credentials?.email || !credentials?.password) {
return null;
}
const platformUser = await prisma.platformUser.findUnique({
where: { email: credentials.email },
});
if (!platformUser) return null;
const valid = await bcrypt.compare(credentials.password, platformUser.password);
if (!valid) return null;
return {
id: platformUser.id,
email: platformUser.email,
name: platformUser.name,
isPlatformUser: true,
platformRole: platformUser.role,
};
},
}),
],
session: {
strategy: "jwt",
maxAge: 8 * 60 * 60, // 8 hours for platform users (more secure)
},
cookies: {
sessionToken: {
name: `platform-auth.session-token`,
options: {
httpOnly: true,
sameSite: "lax",
path: "/platform",
secure: process.env.NODE_ENV === "production",
},
},
},
callbacks: {
async jwt({ token, user }) {
if (user) {
token.isPlatformUser = user.isPlatformUser;
token.platformRole = user.platformRole;
}
return token;
},
async session({ session, token }) {
if (token && session.user) {
session.user.isPlatformUser = token.isPlatformUser;
session.user.platformRole = token.platformRole;
}
return session;
},
},
pages: {
signIn: "/platform/login",
},
secret: process.env.NEXTAUTH_SECRET,
debug: process.env.NODE_ENV === "development",
};