Nuxt DB connection
I am using the Kinde Nuxt SDK and want to know the simplest way to connect a kinde-authed user to a DB to show their unique data? For simplicity I have set up an SQL lite DB with Prisma.
I have noticed that the Next SDK is checking for the server session using the following import statement, but this is not obvious in the Nuxt SDK?
import {getKindeServerSession} from "@kinde-oss/kinde-auth-nextjs/server";
@Oli - Kinde I noticed you recommended webhooks for another Nuxt user.
Thanks!
6 Replies
Hey @DAvid, I would probably go down the route of having a webhook to handle a user registration event, then in the webhook creating a new user in your db with a kinde_id matching the newly registered user
@Peter (Kinde) I looked into webhooks...
I can see they provide events (user created, organisation created etc) how I can sync user data (as below) with my database?
{
id: "kp_12345556666",
given_name: "Sally",
family_name: "Smith",
email: "[email protected]",
picture: "https://lh3.googleusercontent.com/a/1234",
updated_at: 1697769735
}
I have also looked at https://kinde.com/api/docs/#authentication GET /oauth2/user_profile - but I understand I need a token for this - could I get that from the webhook?
My goal is to use Kinde to
a) filter any other data I add to my database by user to show on page load
b) make sure the six fields above are synced
@Peter (Kinde) a quick update - I have made some progress using Kinde's AI tool here
https://discordapp.com/channels/1070212618549219328/1248317289095233568/1248345290952544267
However its recommending import { getKindeServerSession } from '@kinde-oss/kinde-auth-nuxt/server'; which doesn't exist in the Nuxt SDK
Hey @DAvid,
Sorry for the delayed response.
I will get an update from my team.
Thanks Oli, I would appreciate that. I have since been able to set up a Next.JS app with Prisma using this tutorial - https://kinde.com/blog/engineering/set-up-a-nextjs-app-with-prisma-orm-and-kinde-auth/ I just want to do the same with Nuxt and possibly some other frameworks too. Thanks!
Ahh yep, the solution in that blog is pretty good, where you can handle the db syncing (on auth success) in a custom route
/api/auth-success
You could probably do the same in Nuxt, without the need for webhooks - but you would have to set up the nuxt equivalent of Nextjs Route Handlers to redirect to after login