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 };
|
||||
Reference in New Issue
Block a user