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
Matvey15mo 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
AidamOP15mo 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
AidamOP15mo ago
No description
Aidam
AidamOP15mo ago
Because it doesn't xD The user still gets created like normal but the added code is disregarded
Gabriel
Gabriel15mo ago
Do you want AFTER user creation, or before?
Solution
Gabriel
Gabriel15mo 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
AidamOP15mo ago
Yep, I was using a react hook so it didn't work
Want results from more Discord servers?
Add your server