32 lines
904 B
TypeScript
32 lines
904 B
TypeScript
import NextAuth,{ type DefaultSession } from "next-auth";
|
|
import Authentik from "next-auth/providers/authentik";
|
|
|
|
declare module "next-auth" {
|
|
interface Session {
|
|
access_token: string;
|
|
}
|
|
}
|
|
|
|
export const { handlers, auth, signIn, signOut } = NextAuth({
|
|
providers: [Authentik({
|
|
clientId: process.env.AUTH_OIDC_CLIENT_ID,
|
|
clientSecret: process.env.AUTH_OIDC_CLIENT_SECRET,
|
|
issuer: process.env.AUTH_OIDC_ISSUER,
|
|
authorization: { params: { scope: 'openid profile email offline_access' } },
|
|
})],
|
|
callbacks: {
|
|
async jwt({token, account}) {
|
|
if (account) {
|
|
token = Object.assign({}, token, { access_token: account.access_token });
|
|
}
|
|
return token
|
|
},
|
|
async session({session, token}) {
|
|
if(session) {
|
|
session = Object.assign({}, session, {access_token: token.access_token})
|
|
console.log(session);
|
|
}
|
|
return session
|
|
}
|
|
}
|
|
});
|