Nephelophyte
Nephelophyte
TTCTheo's Typesafe Cult
Created by Nephelophyte on 12/11/2023 in #questions
Extending the default PrismaAdapter you get
Was able to make it work like this:
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import { Award, type PrismaClient } from "@prisma/client"
import { type AdapterUser } from "next-auth/adapters"

const CustomAdapter = (client: PrismaClient) => {
const adapter = PrismaAdapter(client);
return {
...adapter,
async createUser(user: Omit<AdapterUser, 'id'>) {
const created = await client.user.create({
data: user,
})

const count = await client.user.count();

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

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

return created as AdapterUser;
},

}
}

export default CustomAdapter;
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import { Award, type PrismaClient } from "@prisma/client"
import { type AdapterUser } from "next-auth/adapters"

const CustomAdapter = (client: PrismaClient) => {
const adapter = PrismaAdapter(client);
return {
...adapter,
async createUser(user: Omit<AdapterUser, 'id'>) {
const created = await client.user.create({
data: user,
})

const count = await client.user.count();

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

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

return created as AdapterUser;
},

}
}

export default CustomAdapter;
5 replies
TTCTheo's Typesafe Cult
Created by Nephelophyte on 12/11/2023 in #questions
Extending the default PrismaAdapter you get
I'm suspecting that the adapter's createUser is opening a transaction that I'm not tapping into, creating a softlock?
5 replies