KindeK
Kinde2y ago
7 replies
DAvid

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");
}


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
Kinde Blog
This guide provides detailed steps on how to seamlessly integrate Kinde, a robust authentication system, with Prisma ORM in a Next.js application.
Set up a Next.js app with Prisma ORM and Kinde Auth
Was this page helpful?