K
Kinde9mo ago
bar2

I want to get the information of the user who successfully registered

I could not see how to do it in the documentation.
7 Replies
bar2
bar2OP9mo ago
because I want to save the registered user in my own database.
IkiTg07
IkiTg079mo ago
Hey @bar2 i've done this many times. There are a lot of ways to achieve this. What sdk are you using ?
bar2
bar2OP9mo ago
I'm using the @kinde-oss/kinde-auth-nextjs SDK for authentication and @prisma/client for database operations.
IkiTg07
IkiTg079mo ago
So you can do two things : - Use
getKindeServerSession()
getKindeServerSession()
and retrieve the user object from there that you will use to create the user in your db. - Use a hook, see here : https://docs.kinde.com/integrate/webhooks/webhooks-nextjs/
Kinde docs
Set up webhooks using Next.js
Our developer tools provide everything you need to get started with Kinde.
IkiTg07
IkiTg079mo ago
Here's one of my implementation :
clientCallback: kindeAuthProcedure.query(async ({ ctx }) => {
if (!ctx) {
console.error("user not found");
throw new TRPCError({ code: "UNAUTHORIZED" });
}

const { error } = await supabase.from("user").insert({
id: ctx.userId,
email: ctx.user.email!,
phone_number: "",
role: "CLIENT",
given_name: ctx.user.given_name!,
family_name: ctx.user.family_name!,
});

if (error) {
console.error("Error in clientCallback", error);
throw new TRPCError({ code: "UNAUTHORIZED" });
}

return { success: true };
}),
clientCallback: kindeAuthProcedure.query(async ({ ctx }) => {
if (!ctx) {
console.error("user not found");
throw new TRPCError({ code: "UNAUTHORIZED" });
}

const { error } = await supabase.from("user").insert({
id: ctx.userId,
email: ctx.user.email!,
phone_number: "",
role: "CLIENT",
given_name: ctx.user.given_name!,
family_name: ctx.user.family_name!,
});

if (error) {
console.error("Error in clientCallback", error);
throw new TRPCError({ code: "UNAUTHORIZED" });
}

return { success: true };
}),
ctx is passed from trpc and it contains the user object I got from doing :
const {getUser} = getKindeServerSession()
const user = await getUser()
const {getUser} = getKindeServerSession()
const user = await getUser()
bar2
bar2OP9mo ago
I understand thank you
IkiTg07
IkiTg079mo ago
No problem

Did you find this page helpful?