Files
Homarr/packages/auth/configuration.ts
Meier Lukas b1e065f1da feat: board access group permissions (#422)
* fix: cache is not exportet from react

* fix: format issue

* wip: add usage of group permissions

* feat: show inherited groups and add manage group

* refactor: improve board access management

* chore: address pull request feedback

* fix: type issues

* fix: migrations

* test: add unit tests for board permissions, permissions and board router

* test: add unit tests for board router and get current user permissions method

* fix: format issues

* fix: deepsource issue
2024-05-04 18:34:41 +02:00

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 { 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;
},
},
});