mirror of
https://gitbruv.vercel.app/api/git/bruv/gitbruv.git
synced 2025-12-20 23:24:09 +01:00
test?
This commit is contained in:
parent
c18ebe04de
commit
23b82c000c
1 changed files with 16 additions and 2 deletions
|
|
@ -37,7 +37,10 @@ async function verifyPassword(password: string, hash: string): Promise<boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
async function authenticateUser(authHeader: string | null): Promise<{ id: string; username: string } | null> {
|
async function authenticateUser(authHeader: string | null): Promise<{ id: string; username: string } | null> {
|
||||||
|
console.log("[Git Auth] Starting authentication");
|
||||||
|
|
||||||
if (!authHeader || !authHeader.startsWith("Basic ")) {
|
if (!authHeader || !authHeader.startsWith("Basic ")) {
|
||||||
|
console.log("[Git Auth] No auth header or not Basic auth");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,7 +48,10 @@ async function authenticateUser(authHeader: string | null): Promise<{ id: string
|
||||||
const credentials = Buffer.from(base64Credentials, "base64").toString("utf-8");
|
const credentials = Buffer.from(base64Credentials, "base64").toString("utf-8");
|
||||||
const [email, password] = credentials.split(":");
|
const [email, password] = credentials.split(":");
|
||||||
|
|
||||||
|
console.log("[Git Auth] Email:", email);
|
||||||
|
|
||||||
if (!email || !password) {
|
if (!email || !password) {
|
||||||
|
console.log("[Git Auth] Missing email or password");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,26 +60,34 @@ async function authenticateUser(authHeader: string | null): Promise<{ id: string
|
||||||
where: eq(users.email, email),
|
where: eq(users.email, email),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("[Git Auth] User found:", !!user);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const account = await db.query.accounts.findFirst({
|
const account = await db.query.accounts.findFirst({
|
||||||
where: and(eq(accounts.userId, user.id), eq(accounts.providerId, "credential")),
|
where: eq(accounts.userId, user.id),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("[Git Auth] Account found:", !!account, "providerId:", account?.providerId, "hasPassword:", !!account?.password);
|
||||||
|
|
||||||
if (!account?.password) {
|
if (!account?.password) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("[Git Auth] Password hash format:", account.password.substring(0, 20) + "...");
|
||||||
|
|
||||||
const valid = await verifyPassword(password, account.password);
|
const valid = await verifyPassword(password, account.password);
|
||||||
|
console.log("[Git Auth] Password valid:", valid);
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { id: user.id, username: user.username };
|
return { id: user.id, username: user.username };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Auth error:", err);
|
console.error("[Git Auth] Error:", err);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue