diff --git a/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx b/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx index 94b49fa20..71d249cf5 100644 --- a/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx +++ b/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx @@ -115,15 +115,7 @@ export const LoginForm = ({ providers, oidcClientName, isOidcAutoLoginEnabled, c {credentialInputsVisible && ( <> -
- void signInAsync(credentials.provider, { - name: credentials.name, - password: credentials.password, - }), - )} - > + void signInAsync(credentials.provider, credentials))}> { - const result = db - .insert(sessions) - .values({ - sessionToken: data.sessionToken, - userId: data.userId, - expires: data.expires, - }) - .returning() - .get(); - - return result; - }, // We override the default implementation as we want to have a provider // flag in the user instead of the account to not intermingle users from different providers // eslint-disable-next-line no-restricted-syntax diff --git a/packages/auth/configuration.ts b/packages/auth/configuration.ts index 21a44a293..b0181e326 100644 --- a/packages/auth/configuration.ts +++ b/packages/auth/configuration.ts @@ -71,12 +71,6 @@ export const createConfiguration = ( const expires = expireDateAfter(env.AUTH_SESSION_EXPIRY_TIME); const sessionToken = generateSessionToken(); - - if (Number.isNaN(expires.getTime())) { - logger.error("Invalid session expiry date", { expirySeconds: env.AUTH_SESSION_EXPIRY_TIME }); - return false; - } - await adapter.createSession({ sessionToken, expires, diff --git a/packages/auth/events.ts b/packages/auth/events.ts index acd53cc8b..2593c418b 100644 --- a/packages/auth/events.ts +++ b/packages/auth/events.ts @@ -99,7 +99,7 @@ const addUserToEveryoneGroupIfNotMemberAsync = async (db: Database, userId: stri }, }); - if (dbEveryoneGroup?.id && dbEveryoneGroup.members.length === 0) { + if (dbEveryoneGroup?.members.length === 0) { await db.insert(groupMembers).values({ userId, groupId: dbEveryoneGroup.id, diff --git a/packages/auth/test/adapter.spec.ts b/packages/auth/test/adapter.spec.ts index b2b0a4ca5..d20ae3d1a 100644 --- a/packages/auth/test/adapter.spec.ts +++ b/packages/auth/test/adapter.spec.ts @@ -1,42 +1,11 @@ -/** - * @vitest-environment node - */ import { describe, expect, test } from "vitest"; -import { createId } from "@homarr/common"; import { users } from "@homarr/db/schema"; import { createDb } from "@homarr/db/test"; import { createAdapter } from "../adapter"; -import { expireDateAfter } from "../session"; describe("createAdapter should create drizzle adapter", () => { - test("createSession should insert a session row", async () => { - const db = createDb(); - const userId = createId(); - await db.insert(users).values({ id: userId, name: "demodemo", password: "hash" }); - - const adapter = createAdapter(db, "credentials"); - const sessionToken = "test-session-token"; - - const session = await adapter.createSession?.({ - sessionToken, - userId, - expires: expireDateAfter(86400), - }); - - expect(session).toMatchObject({ - sessionToken, - userId, - }); - - const storedSession = await db.query.sessions.findFirst({ - where: (table, { eq }) => eq(table.sessionToken, sessionToken), - }); - - expect(storedSession).toBeDefined(); - }); - test.each([["credentials" as const], ["ldap" as const], ["oidc" as const]])( "createAdapter getUserByEmail should return user for provider %s when this provider provided", async (provider) => { diff --git a/packages/core/src/infrastructure/env/schemas.ts b/packages/core/src/infrastructure/env/schemas.ts index 4d415b4f1..595dd37ca 100644 --- a/packages/core/src/infrastructure/env/schemas.ts +++ b/packages/core/src/infrastructure/env/schemas.ts @@ -12,26 +12,25 @@ export const createBooleanSchema = (defaultValue: boolean) => }) .default(defaultValue); -export const createDurationSchema = (defaultValue: `${number}${"s" | "m" | "h" | "d"}`) => { - const defaultMultipliers = { - s: 1, - m: 60, - h: 60 * 60, - d: 60 * 60 * 24, - } as const; - - return z +export const createDurationSchema = (defaultValue: `${number}${"s" | "m" | "h" | "d"}`) => + z .string() .regex(/^\d+[smhd]?$/) .default(defaultValue) .transform((duration) => { - const unit = duration.at(-1) as keyof typeof defaultMultipliers | undefined; - const multiplier = unit ? defaultMultipliers[unit] : undefined; - - if (multiplier) { - return Number(duration.slice(0, -1)) * multiplier; + const lastChar = duration[duration.length - 1] as "s" | "m" | "h" | "d"; + if (!isNaN(Number(lastChar))) { + return Number(defaultValue); } - return Number(duration); + const multipliers = { + s: 1, + m: 60, + h: 60 * 60, + d: 60 * 60 * 24, + }; + const numberDuration = Number(duration.slice(0, -1)); + const multiplier = multipliers[lastChar]; + + return numberDuration * multiplier; }); -};