feat(schema): add githubUsername field to User model for contributor attribution
This commit is contained in:
+13
-12
@@ -20,18 +20,19 @@ enum UserRole {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
email String @unique
|
email String @unique
|
||||||
username String @unique
|
username String @unique
|
||||||
name String?
|
name String?
|
||||||
password String? // For credentials auth
|
password String? // For credentials auth
|
||||||
avatar String?
|
avatar String?
|
||||||
role UserRole @default(USER)
|
role UserRole @default(USER)
|
||||||
locale String @default("en")
|
locale String @default("en")
|
||||||
verified Boolean @default(false)
|
verified Boolean @default(false)
|
||||||
emailVerified DateTime?
|
emailVerified DateTime?
|
||||||
createdAt DateTime @default(now())
|
githubUsername String? // Immutable GitHub username for contributor attribution
|
||||||
updatedAt DateTime @updatedAt
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
|
||||||
// Relations
|
// Relations
|
||||||
prompts Prompt[] @relation("PromptAuthor")
|
prompts Prompt[] @relation("PromptAuthor")
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ export async function GET() {
|
|||||||
},
|
},
|
||||||
author: {
|
author: {
|
||||||
select: {
|
select: {
|
||||||
username: true,
|
email: true,
|
||||||
|
githubUsername: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -42,7 +43,9 @@ export async function GET() {
|
|||||||
const promptContent = escapeCSVField(prompt.content);
|
const promptContent = escapeCSVField(prompt.content);
|
||||||
const forDevs = prompt.category?.slug === "coding" ? "TRUE" : "FALSE";
|
const forDevs = prompt.category?.slug === "coding" ? "TRUE" : "FALSE";
|
||||||
const type = prompt.type;
|
const type = prompt.type;
|
||||||
const contributor = escapeCSVField(prompt.author.username);
|
// Use githubUsername for GitHub users, email for others (Google, credentials)
|
||||||
|
// This prevents impersonation since these identifiers are immutable
|
||||||
|
const contributor = escapeCSVField(prompt.author.githubUsername || prompt.author.email);
|
||||||
|
|
||||||
return [act, promptContent, forDevs, type, contributor].join(",");
|
return [act, promptContent, forDevs, type, contributor].join(",");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -41,9 +41,11 @@ function CustomPrismaAdapter(): Adapter {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...prismaAdapter,
|
...prismaAdapter,
|
||||||
async createUser(data: AdapterUser & { username?: string }) {
|
async createUser(data: AdapterUser & { username?: string; githubUsername?: string }) {
|
||||||
// Use GitHub username if provided, otherwise generate one
|
// Use GitHub username if provided, otherwise generate one
|
||||||
let username = (data as any).username;
|
let username = (data as any).username;
|
||||||
|
const githubUsername = (data as any).githubUsername; // Immutable GitHub username
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
username = await generateUsername(data.email, data.name);
|
username = await generateUsername(data.email, data.name);
|
||||||
} else {
|
} else {
|
||||||
@@ -64,6 +66,7 @@ function CustomPrismaAdapter(): Adapter {
|
|||||||
email: data.email,
|
email: data.email,
|
||||||
avatar: data.image,
|
avatar: data.image,
|
||||||
emailVerified: data.emailVerified,
|
emailVerified: data.emailVerified,
|
||||||
|
githubUsername: githubUsername || undefined, // Store immutable GitHub username
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -91,6 +94,7 @@ function CustomPrismaAdapter(): Adapter {
|
|||||||
avatar: data.image,
|
avatar: data.image,
|
||||||
emailVerified: data.emailVerified,
|
emailVerified: data.emailVerified,
|
||||||
username,
|
username,
|
||||||
|
githubUsername: githubUsername || undefined, // Store immutable GitHub username
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ export const githubPlugin: AuthPlugin = {
|
|||||||
name: profile.name || profile.login,
|
name: profile.name || profile.login,
|
||||||
email: profile.email,
|
email: profile.email,
|
||||||
image: profile.avatar_url,
|
image: profile.avatar_url,
|
||||||
username: profile.login, // GitHub username
|
username: profile.login, // GitHub username (used as display username)
|
||||||
|
githubUsername: profile.login, // Immutable GitHub username for contributor attribution
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user