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
Matvey16mo 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
AidamOP16mo 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
AidamOP16mo ago
No description
Aidam
AidamOP16mo ago
Because it doesn't xD The user still gets created like normal but the added code is disregarded
Gabriel
Gabriel16mo ago
Do you want AFTER user creation, or before?
Solution
Gabriel
Gabriel16mo 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
AidamOP16mo ago
Yep, I was using a react hook so it didn't work

Did you find this page helpful?