260320:1709 Refactor Overrall #10 Fix by antigravity: pnpm frontend deploy
Build and Deploy / deploy (push) Successful in 7m25s

This commit is contained in:
admin
2026-03-20 17:09:10 +07:00
parent 2d56c07eae
commit dcf55f4d08
2 changed files with 27 additions and 7 deletions
+26 -7
View File
@@ -70,28 +70,46 @@ export const {
password: { label: "Password", type: "password" },
},
authorize: async (credentials) => {
try {
const { username, password } = await loginSchema.parseAsync(credentials);
if (!credentials?.username || !credentials?.password) return null;
try {
// 1. Sanitize payload (Only send username and password)
const payload = {
username: credentials.username as string,
password: credentials.password as string,
};
console.log(`[AUTH] Attempting login at: ${baseUrl}/auth/login`);
console.log(`[AUTH] Current process.env.INTERNAL_API_URL: ${process.env.INTERNAL_API_URL}`);
console.log(`[AUTH] Current process.env.NEXT_PUBLIC_API_URL: ${process.env.NEXT_PUBLIC_API_URL}`);
const res = await fetch(`${baseUrl}/auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
body: JSON.stringify(payload),
headers: {
"Content-Type": "application/json",
},
cache: 'no-store', // Disable caching for auth requests
});
if (!res.ok) {
const errorMsg = await res.text();
console.error(`[AUTH] Login Failed: status ${res.status}`);
const errorBody = await res.text().catch(() => "No error body");
console.error(`[AUTH] Error details: ${errorBody}`);
return null;
}
const responseJson = await res.json();
const backendData = responseJson.data || responseJson;
const data = await res.json();
// Handling both { data: { ... } } and direct { ... } response formats
const backendData = data.data || data;
if (!backendData || !backendData.access_token) {
console.error("[AUTH] Login failed: Invalid response format from backend (missing access_token)");
return null;
}
console.log(`[AUTH] Login Successful for user: ${backendData.user?.username || 'unknown'}`);
return {
id: backendData.user.user_id.toString(),
name: `${backendData.user.firstName} ${backendData.user.lastName}`,
@@ -104,6 +122,7 @@ export const {
} as User;
} catch (error) {
console.error("[AUTH] Network/Fetch Error during authorize:", error);
return null;
}
},