Run additional code on user creation

I want to run additional code on user creation, how do I achieve this?
Solution:
Is that api you are importing from client or server? It looks like you are using useMutation, which is a react hook. You want to use the api from the server
Jump to solution
7 Replies
Matvey
Matvey11mo ago
Events | NextAuth.js
Events are asynchronous functions that do not return a response, they are useful for audit logs / reporting or handling any other side-effects.
Aidam
Aidam11mo ago
auth.ts
export const authOptions: NextAuthOptions = {
...
events: {
async createUser(){
const createGroupMutation = api.groups.create.useMutation();
const createGroup = async (name: string) => {
await createGroupMutation.mutateAsync({
name,
memberIDs: []
})
}
await createGroup("session created");
},
},
export const authOptions: NextAuthOptions = {
...
events: {
async createUser(){
const createGroupMutation = api.groups.create.useMutation();
const createGroup = async (name: string) => {
await createGroupMutation.mutateAsync({
name,
memberIDs: []
})
}
await createGroup("session created");
},
},
So something like this should work?
Aidam
Aidam11mo ago
No description
Aidam
Aidam11mo ago
Because it doesn't xD The user still gets created like normal but the added code is disregarded
Gabriel
Gabriel11mo ago
Do you want AFTER user creation, or before?
Solution
Gabriel
Gabriel11mo ago
Is that api you are importing from client or server? It looks like you are using useMutation, which is a react hook. You want to use the api from the server
Aidam
Aidam11mo ago
Yep, I was using a react hook so it didn't work
Want results from more Discord servers?
Add your server