50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
|
|
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 }; |