Nephelophyte
Nephelophyte
TTCTheo's Typesafe Cult
Created by Nephelophyte on 12/11/2023 in #questions
Extending the default PrismaAdapter you get
I want to extend the default prisma adapter to be able to award a badge to the first 100 users to sign up for my site. Unfortunately, the following code actually breaks nextjs entirely and becomes a zombie process. Not quite sure what I'm doing wrong here:
const extendedAdapter: typeof PrismaAdapter = (db) => {
const adapter = PrismaAdapter(db);
assert(adapter.createUser !== undefined);
return {
...adapter,
createUser: async (user) => {
const created = await adapter.createUser!(user);

const userCount = await db.user.count();
console.log('BADGE', db.userBadge);

if (userCount <= 100) {
await db.userBadge.create({
data: {
award: Award.FIRST_100_USER,
userId: created.id,
}
});
}

if (userCount <= 1000 && userCount > 100) {
await db.userBadge.create({
data: {
award: Award.FIRST_1000_USER,
userId: created.id,
}
});
}

return created;
}
}
}
const extendedAdapter: typeof PrismaAdapter = (db) => {
const adapter = PrismaAdapter(db);
assert(adapter.createUser !== undefined);
return {
...adapter,
createUser: async (user) => {
const created = await adapter.createUser!(user);

const userCount = await db.user.count();
console.log('BADGE', db.userBadge);

if (userCount <= 100) {
await db.userBadge.create({
data: {
award: Award.FIRST_100_USER,
userId: created.id,
}
});
}

if (userCount <= 1000 && userCount > 100) {
await db.userBadge.create({
data: {
award: Award.FIRST_1000_USER,
userId: created.id,
}
});
}

return created;
}
}
}
Then later on ` export const authOptions: NextAuthOptions = { {...} adapter: extendedAdapter(db), {...} }
5 replies