mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-30 11:19:12 +01:00
* feat: update prettier configuration for print width * chore: apply code formatting to entire repository * fix: remove build files * fix: format issue --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
56 lines
1.7 KiB
TypeScript
56 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 { createSessionCallback, createSignInCallback } 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: createSessionCallback(db),
|
|
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;
|
|
},
|
|
},
|
|
});
|