z
z
Explore posts from servers
PPrisma
Created by z on 9/27/2024 in #help-and-questions
Error when using accelerate (Local Development)
ref: https://www.prisma.io/docs/accelerate/local-development i did run prisma generate after updating DB URL. im using sveltekit and postgres db. .env
DATABASE_URL="postgresql://postgres:root@localhost:5432/docker"
DIRECT_DATABASE_URL="postgresql://postgres:root@localhost:5432/docker"
DATABASE_URL="postgresql://postgres:root@localhost:5432/docker"
DIRECT_DATABASE_URL="postgresql://postgres:root@localhost:5432/docker"
error
[redacted]/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_/node_modules/@prisma/extension-accelerate/dist/esm/extension.js:75
.then(() => client._engine.apiKey());
^

TypeError: client._engine.apiKey is not a function
at [redacted]/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_/node_modules/@prisma/extension-accelerate/dist/esm/extension.js:75:40

Node.js v20.10.0
[redacted]/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_/node_modules/@prisma/extension-accelerate/dist/esm/extension.js:75
.then(() => client._engine.apiKey());
^

TypeError: client._engine.apiKey is not a function
at [redacted]/node_modules/.pnpm/@[email protected]_@[email protected][email protected]_/node_modules/@prisma/extension-accelerate/dist/esm/extension.js:75:40

Node.js v20.10.0
schema.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch", "tracing"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch", "tracing"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
database.ts
import { PrismaClient } from '@prisma/client';
import { withAccelerate } from '@prisma/extension-accelerate';

const prisma = new PrismaClient().$extends(withAccelerate());

export { prisma as db };
import { PrismaClient } from '@prisma/client';
import { withAccelerate } from '@prisma/extension-accelerate';

const prisma = new PrismaClient().$extends(withAccelerate());

export { prisma as db };
versions
"dependencies": {
...
"@prisma/client": "^5.20.0",
"@prisma/extension-accelerate": "^1.2.0",
"@prisma/extension-optimize": "^1.0.1",
"prisma": "^5.20.0",
...
}
"dependencies": {
...
"@prisma/client": "^5.20.0",
"@prisma/extension-accelerate": "^1.2.0",
"@prisma/extension-optimize": "^1.0.1",
"prisma": "^5.20.0",
...
}
27 replies
TTCTheo's Typesafe Cult
Created by z on 6/26/2023 in #questions
NextJS "Module not found" error with "loading.tsx"?
13 replies
TTCTheo's Typesafe Cult
Created by z on 6/10/2023 in #questions
Uploadthing + NextJS (App Dir) API Loop Bug
As shown in the video, i dont think there much else to say...
19 replies
TTCTheo's Typesafe Cult
Created by z on 6/1/2023 in #questions
NextJS and Bare Metal
What all features would break/may not work if I decide to deploy to NEXTjs to bare metal instead of serverless?
5 replies
TTCTheo's Typesafe Cult
Created by z on 5/6/2023 in #questions
Server Actions and tRPC
Is server actions a replacement for tRPC? Or am I just fundamentally wrong about server actions and they have nothing to do with each other?
3 replies
TTCTheo's Typesafe Cult
Created by z on 3/29/2023 in #questions
Modifying 'Session' in next-auth
Code (I removed imports and comments as they are not required):
declare module "next-auth" {
interface Session {
user: {
id: string;
username: string;
password: string;
};
}

interface User {
id: string;
username: string;
password: string;
}
}

export const authOptions: NextAuthOptions = {
session: {
strategy: "jwt",
},
callbacks: {
session({ session, token }) {
console.log("session", session)
console.log("token", token)
if (token && session.user) {
session.user.id = token.id as string;
}

return session;
},
jwt: async ({ token, user }) => {
console.log("user", user)
if (user) {
token.id = user.id;
}

return token;
},
},
// adapter: PrismaAdapter(prisma),
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
username: { label: "Username", type: "text", placeholder: "admin" },
password: { label: "Password", type: "password" }
},
authorize(credentials) {
console.log(credentials)
const {username, password} = credentials
if (username !== "admin" || password !== "admin") {
throw new Error("invalid credentials");
}
const user = {
id: "1234",
username: "admin",
password: "admin",
}
return user
},
}),
],
};

/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = (ctx: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
}) => {
return getServerSession(ctx.req, ctx.res, authOptions);
};
declare module "next-auth" {
interface Session {
user: {
id: string;
username: string;
password: string;
};
}

interface User {
id: string;
username: string;
password: string;
}
}

export const authOptions: NextAuthOptions = {
session: {
strategy: "jwt",
},
callbacks: {
session({ session, token }) {
console.log("session", session)
console.log("token", token)
if (token && session.user) {
session.user.id = token.id as string;
}

return session;
},
jwt: async ({ token, user }) => {
console.log("user", user)
if (user) {
token.id = user.id;
}

return token;
},
},
// adapter: PrismaAdapter(prisma),
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
username: { label: "Username", type: "text", placeholder: "admin" },
password: { label: "Password", type: "password" }
},
authorize(credentials) {
console.log(credentials)
const {username, password} = credentials
if (username !== "admin" || password !== "admin") {
throw new Error("invalid credentials");
}
const user = {
id: "1234",
username: "admin",
password: "admin",
}
return user
},
}),
],
};

/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = (ctx: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
}) => {
return getServerSession(ctx.req, ctx.res, authOptions);
};
4 replies
TTCTheo's Typesafe Cult
Created by z on 3/7/2023 in #questions
When to use next-auth
If I only plan on only using credentials i.e not using providers like discord, github, etc. Is it worth using next-auth or am I better of making my own custom authentication?
8 replies