Authentication And Serive Engineer Portal is added

This commit is contained in:
2026-07-18 13:44:32 +05:30
parent 3222da96ab
commit a0426e8c8a
17 changed files with 762 additions and 221 deletions

View File

@@ -0,0 +1,50 @@
import NextAuth, { NextAuthOptions } from "next-auth";
import KeycloakProvider from "next-auth/providers/keycloak";
export const authOptions: NextAuthOptions = {
providers: [
KeycloakProvider({
clientId: process.env.KEYCLOAK_CLIENT_ID!,
clientSecret: process.env.KEYCLOAK_CLIENT_SECRET!,
issuer: process.env.KEYCLOAK_ISSUER!,
}),
],
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
async jwt({ token, account, profile }) {
console.log("PROFILE =>", profile)
if (account && profile) {
token.name =
(profile as any).name ||
(profile as any).preferred_username ||
"Unknown User"
token.email = (profile as any).email || "no-email"
}
console.log("TOKEN =>", token)
return token
},
async session({ session, token }) {
session.user = {
...session.user,
name: token.name as string,
email: token.email as string,
}
console.log("SESSION =>", session)
return session
},
},
debug: true,
};
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };

View File

@@ -0,0 +1,14 @@
"use client";
import ServiceEngineerPortal from "@/components/dashboard/serviceEngineer";
export default function EngagementDashboard() {
return (
<div className="p-6">
<ServiceEngineerPortal/>
</div>
);
}

View File

@@ -1,7 +1,17 @@
// app/dashboard/page.tsx
import { redirect } from "next/navigation";
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/app/api/auth/[...nextauth]/route"; // Changed from handler to authOptions
export default function DashboardBasePage() {
// Automatically redirect the user to the actual overview dashboard page
redirect("/dashboard/overview/dashboard");
}
export default async function DashboardBasePage() {
const session = await getServerSession(authOptions);
if (!session) {
redirect("/login");
}
else{
redirect("/dashboard/overview/dashboard");
}
}

View File

@@ -1,6 +1,6 @@
import "./globals.css";
import SessionWrapper from "./sessionWrapper";
export default function RootLayout({
@@ -12,7 +12,11 @@ export default function RootLayout({
<html
lang="en"
>
<body >{children}</body>
<body>
<SessionWrapper>
{children}
</SessionWrapper>
</body>
</html>
);
}

View File

@@ -4,7 +4,7 @@ import OverViewDashboardPage from "./dashboard/overview/buildingOwner/page";
export default function Home() {
return (
<div>
<OverViewDashboardPage/>
{/* <OverViewDashboardPage/> */}
</div>
);
}

14
app/sessionWrapper.tsx Normal file
View File

@@ -0,0 +1,14 @@
"use client";
import React from "react";
import { SessionProvider } from "next-auth/react";
interface SessionWrapperProps {
children: React.ReactNode;
}
export default function SessionWrapper({
children,
}: SessionWrapperProps) {
return <SessionProvider>{children}</SessionProvider>;
}