From 7d985670913e3a531e2b0a4f3db601622bdc28c7 Mon Sep 17 00:00:00 2001 From: Saiful Alom Date: Wed, 17 Jun 2026 11:11:26 +0600 Subject: [PATCH] fix(auth): handle production login errors via Astro ActionError - Replace generic native Error with Astro's `ActionError` utility - Set the error code explicitly to `UNAUTHORIZED` for production safety - Improve error message clarity for incorrect credential submissions --- src/modules/auth/auth.actions.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/auth/auth.actions.ts b/src/modules/auth/auth.actions.ts index 159e508..936a3b2 100644 --- a/src/modules/auth/auth.actions.ts +++ b/src/modules/auth/auth.actions.ts @@ -1,4 +1,4 @@ -import { defineAction } from 'astro:actions'; +import { defineAction,ActionError } from 'astro:actions'; import { SignJWT } from 'jose'; import { loginSchema } from './auth.schema'; @@ -11,7 +11,11 @@ export const login = defineAction({ // 1. Validate Credentials against Environment Secrets if (email !== env.ADMIN_EMAIL || password !== env.ADMIN_PASSWORD) { - throw new Error("Invalid credentials"); + // High security, standard code format for authentication blocks + throw new ActionError({ + code: "UNAUTHORIZED", + message: "Invalid email or password." + }); } // 2. Prepare JWT Secret @@ -35,7 +39,7 @@ export const login = defineAction({ return { success: true }; }, -}) +}); export const logout = defineAction({ handler: async (_, context) => {