sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.23k stars 158 forks source link

Not compatible with @prisma/nuxt #784

Closed ankur198 closed 1 month ago

ankur198 commented 2 months ago

Environment

Nuxt project info: 7:51:21 AM


Reproduction

npx nuxi@latest init test-nuxt-app

cd test-nuxt-app
npx nuxi@latest module add @prisma/nuxt
npx nuxi@latest module add @sidebase/nuxt-auth

now npm run dev fails

Describe the bug

RollupError: node_modules/@prisma/nuxt/dist/runtime/server/utils/prisma.d.ts (2:8): Expected ';', '}' or (Note that you need plugins to import files that are not JavaScript)

1: import { PrismaClient } from "@prisma/client"; 2: declare const prismaClientSingleton: () => PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, i... ^ 3: declare const prisma: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client... 4: export type CustomPrismaClient = ReturnType;

Additional context

No response

Logs

No response

zoey-kaiser commented 1 month ago

Hi @ankur198 👋

Why do you belive this is an issue with @sidebase/nuxt-auth? Have you checked with the team behind @prisma/nuxt where this error may be coming from?

As a quick workaround for this issue, you could install Prisma without the Nuxt module as we also recommend in create-sidebase (npm create sidebase@latest):

pnpm i -D prisma
pnpm i @prisma/client
// file: ~/server/middleware/0.prisma.ts

import { PrismaClient } from '@prisma/client'

let prisma: PrismaClient

declare module 'h3' {
  interface H3EventContext {
    prisma: PrismaClient
  }
}

export default eventHandler((event) => {
  if (!prisma) {
    prisma = new PrismaClient()
  }
  event.context.prisma = prisma
})
// file: ~/prisma/utils.ts
import { execSync } from 'node:child_process'

/**
 * Helper to reset the database via a programmatic prisma invocation. Helpful to add to \`beforeEach\` or \`beforeAll\` of your testing setup.
 *
 * WARNING: Never run this in production.
 *
 * Taken from https://github.com/prisma/prisma/issues/13549#issuecomment-1144883246
 *
 * @param databaseUrl Connection URL to database. Inferred from \`process.env.DATABASE_URL\` if not provided
 */
export function resetDatabase(databaseUrl?: string) {
  const url = databaseUrl || process.env.DATABASE_URL
  if (!url) {
    throw new Error('Cannot reset database - connection string could not be inferred.')
  }

  if (process.env.NODE_ENV === 'production') {
    throw new Error('This utility should not be called in production. It is meant for testing and development')
  }

  execSync(\`cd \${process.cwd()} && DATABASE_URL=\${url} npx prisma db push --force-reset\`, { stdio: 'inherit' })
}
ankur198 commented 1 month ago

Hi @zoey-kaiser ,

Thanks for responding and yes you are correct. I have seen @prisma/nuxt is not compatible with a lot of other libraries. My bad. Closing the issue.

Thanks for providing workaround though 🙂