Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/modules/auth/auth.actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineAction } from 'astro:actions';
import { defineAction,ActionError } from 'astro:actions';
import { SignJWT } from 'jose';
import { loginSchema } from './auth.schema';

Expand All @@ -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
Expand All @@ -35,7 +39,7 @@ export const login = defineAction({

return { success: true };
},
})
});

export const logout = defineAction({
handler: async (_, context) => {
Expand Down
Loading