Authentication And Serive Engineer Portal is added
This commit is contained in:
50
app/api/auth/[...nextauth]/route.ts
Normal file
50
app/api/auth/[...nextauth]/route.ts
Normal 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 };
|
||||
@@ -0,0 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import ServiceEngineerPortal from "@/components/dashboard/serviceEngineer";
|
||||
|
||||
export default function EngagementDashboard() {
|
||||
return (
|
||||
|
||||
|
||||
<div className="p-6">
|
||||
<ServiceEngineerPortal/>
|
||||
</div>
|
||||
|
||||
);
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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
14
app/sessionWrapper.tsx
Normal 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>;
|
||||
}
|
||||
Reference in New Issue
Block a user