lucia-auth / lucia

Authentication, simple and clean
https://lucia-auth.com
MIT License
8.35k stars 448 forks source link

[Bug]: @lucia-auth/adapter-postgresql has no export member 'pg' #1539

Closed zmzlois closed 2 months ago

zmzlois commented 2 months ago

Package

​@lucia-auth/adapter-postgresql

Describe the bug

I am using Next.js 13.4.8 with vercel postgres and it seems like the error is telling me there is no exported member postgres, which never happened when I am using lucia in other places

Screenshot 2024-04-18 at 00 18 15

My dependencies:

"next": "^13.4.8",
 "oslo": "^1.2.0",
  "@lucia-auth/adapter-postgresql": "^3.1.2",
 "@vercel/postgres": "^0.8.0",

where I am using it src/auth.ts

code:

// src/auth.ts
import { Lucia } from "lucia";

import { pg } from "@lucia-auth/adapter-postgresql";
import { db } from "@vercel/postgres";

const adapter = new pg(db); // your adapter

export const lucia = new Lucia(adapter, {
    sessionCookie: {
        // this sets cookies with super long expiration
        // since Next.js doesn't allow Lucia to extend cookie expiration when rendering pages
        expires: false,
        attributes: {
            // set to `true` when using HTTPS
            secure: process.env.NODE_ENV === "production"
        }
    }
});

// IMPORTANT!
declare module "lucia" {
    interface Register {
        Lucia: typeof lucia;
    }
}

tsconfig

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "incremental": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "baseUrl": ".",
    "paths": {
      "@/*": ["./*"]
    },
    "plugins": [
      {
        "name": "next"
      }
    ],
    "strictNullChecks": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}
zmzlois commented 2 months ago

Another question is how should I set up vercel/postgres with drizzle and lucia? it seems like the auth is baked in and I am not sure how should this looks like Screenshot 2024-04-18 at 00 38 00

Screenshot 2024-04-18 at 00 37 40

pilcrowOnPaper commented 2 months ago

You're probably following an old tutorial. See: https://lucia-auth.com/database/postgresql

You'd want to use the Drizzle adapter: https://lucia-auth.com/database/drizzle