refactor: dynamically generated login page

This commit is contained in:
Dominik 2025-05-12 21:22:56 +02:00 committed by Dominik
parent ddcb14e564
commit 20eb6ae04a
4 changed files with 75 additions and 17 deletions

View file

@ -1,16 +1,49 @@
import NextAuth from 'next-auth';
import type { Provider } from 'next-auth/providers';
import Credentials from 'next-auth/providers/credentials';
import Authentik from 'next-auth/providers/authentik';
const providers: Provider[] = [
!process.env.DISABLE_PASSWORD_LOGIN &&
Credentials({
credentials: { password: { label: 'Password', type: 'password' } },
authorize(c) {
if (c.password !== 'password') return null;
return {
id: 'test',
name: 'Test User',
email: 'test@example.com',
};
},
}),
process.env.AUTH_AUTHENTIK_ID && Authentik,
].filter(Boolean) as Provider[];
export const providerMap = providers
.map((provider) => {
if (typeof provider === 'function') {
const providerData = provider();
return { id: providerData.id, name: providerData.name };
} else {
return { id: provider.id, name: provider.name };
}
})
.filter((provider) => provider.id !== 'credentials');
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [process.env.AUTH_AUTHENTIK_ISSUER ? Authentik : null].filter(
(x) => x !== null,
),
callbacks: {
authorized: async ({ auth }) => {
return !!auth?.user;
},
providers,
session: {
strategy: 'jwt',
},
pages: {
signIn: '/login',
signOut: '/logout',
},
callbacks: {
authorized({ auth }) {
return !!auth?.user;
},
},
});