DAvid
DAvid
KKinde
Created by DAvid on 7/15/2024 in #💻┃support
Nuxt with Prisma ORM and Kinde Auth
Hello, I'm trying to find an equivalent of the following code for Nuxt.js to connect a user signing in with Kinde to a Prisma powered database before initial page load.
import {PrismaClient} from "@prisma/client";
import {getKindeServerSession} from "@kinde-oss/kinde-auth-nextjs/server";
import {NextResponse} from "next/server";

const prisma = new PrismaClient();

export async function GET() {
const {getUser} = getKindeServerSession();
const user = await getUser();

if (!user || user == null || !user.id)
throw new Error("something went wrong with authentication" + user);

let dbUser = await prisma.user.findUnique({
where: {kindeId: user.id}
});

if (!dbUser) {
dbUser = await prisma.user.create({
data: {
kindeId: user.id,
firstName: user.given_name ?? "",
lastName: user.family_name ?? "",
email: user.email ?? "" // Using nullish coalescing operator to provide a default empty string value
}
});
}

return NextResponse.redirect("http://localhost:3000/dashboard");
}
import {PrismaClient} from "@prisma/client";
import {getKindeServerSession} from "@kinde-oss/kinde-auth-nextjs/server";
import {NextResponse} from "next/server";

const prisma = new PrismaClient();

export async function GET() {
const {getUser} = getKindeServerSession();
const user = await getUser();

if (!user || user == null || !user.id)
throw new Error("something went wrong with authentication" + user);

let dbUser = await prisma.user.findUnique({
where: {kindeId: user.id}
});

if (!dbUser) {
dbUser = await prisma.user.create({
data: {
kindeId: user.id,
firstName: user.given_name ?? "",
lastName: user.family_name ?? "",
email: user.email ?? "" // Using nullish coalescing operator to provide a default empty string value
}
});
}

return NextResponse.redirect("http://localhost:3000/dashboard");
}
The code comes from this tutorial https://kinde.com/blog/engineering/set-up-a-nextjs-app-with-prisma-orm-and-kinde-auth/ and uses the {getKindeServerSession} helper from the Next SDK to access user details from the server before the page loads — I can not see this helper in either the Nuxt or Typescript SDK. Thanks
8 replies
KKinde
Created by DAvid on 5/15/2024 in #💻┃support
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!
9 replies