mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-29 18:59:20 +01:00
* feat: make tasks script run in docker * feat: make websocket server work in docker * fix: format issue * fix: broken lockfile * fix: non matching typescript versions
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { cookies } from "next/headers";
|
|
import { DrizzleAdapter } from "@auth/drizzle-adapter";
|
|
import NextAuth from "next-auth";
|
|
import Credentials from "next-auth/providers/credentials";
|
|
|
|
import { db } from "@homarr/db";
|
|
|
|
import { createSignInCallback, sessionCallback } from "./callbacks";
|
|
import { createCredentialsConfiguration } from "./providers/credentials";
|
|
import { EmptyNextAuthProvider } from "./providers/empty";
|
|
import { sessionMaxAgeInSeconds, sessionTokenCookieName } from "./session";
|
|
|
|
const adapter = DrizzleAdapter(db);
|
|
|
|
export const createConfiguration = (isCredentialsRequest: boolean) =>
|
|
NextAuth({
|
|
logger: {
|
|
error: (code, ...message) => {
|
|
// Remove the big error message for failed login attempts
|
|
// as it is not useful for the user.
|
|
if (code.name === "CredentialsSignin") {
|
|
console.warn("The login attempt of a user was not successful.");
|
|
return;
|
|
}
|
|
|
|
console.error(code, ...message);
|
|
},
|
|
},
|
|
trustHost: true,
|
|
adapter,
|
|
providers: [
|
|
Credentials(createCredentialsConfiguration(db)),
|
|
EmptyNextAuthProvider(),
|
|
],
|
|
callbacks: {
|
|
session: sessionCallback,
|
|
signIn: createSignInCallback(adapter, isCredentialsRequest),
|
|
},
|
|
secret: "secret-is-not-defined-yet", // TODO: This should be added later
|
|
session: {
|
|
strategy: "database",
|
|
maxAge: sessionMaxAgeInSeconds,
|
|
},
|
|
pages: {
|
|
signIn: "/auth/login",
|
|
error: "/auth/login",
|
|
},
|
|
jwt: {
|
|
encode() {
|
|
const cookie = cookies().get(sessionTokenCookieName)?.value;
|
|
return cookie ?? "";
|
|
},
|
|
|
|
decode() {
|
|
return null;
|
|
},
|
|
},
|
|
});
|