Zurnadürüm
Zurnadürüm
Explore posts from servers
PPrisma
Created by Zurnadürüm on 7/24/2024 in #help-and-questions
Prisma doesn't see .env.development
Hi! I want to seperate my dev and prod env on my NextJS project. NextJS follow this rule by default, next dev use .env.development and next build use .env or .env.production. But Prisma doesn't follow this rule. When I want to migrate/generate prisma-client on my test env, that DB URLs located at .env.development, Prisma always use .env, and tries to connect prod database. My package.json file scripts look like that:
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"vercel-build": "prisma generate && prisma migrate deploy && next build",
"migrate:dev": "dotenv -e .env.development -- pnpx prisma migrate dev"
}
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"vercel-build": "prisma generate && prisma migrate deploy && next build",
"migrate:dev": "dotenv -e .env.development -- pnpx prisma migrate dev"
}
But I get error P1013 when I try to run migrate:dev script. How can I solve this? - Tried to rename .env -> .env.production. - Installed dotenv-cli and dotenv that said on Prisma docs. My Postgresql DB sits on Docker. Prisma was working before seperating my prod(deploying initial version) and test env. FYI, my schema.prisma connection is that:
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}
4 replies
TTCTheo's Typesafe Cult
Created by Zurnadürüm on 4/12/2024 in #questions
Next redirect() gives date.getTime() error
I use lucia auth with nextjs. And all things are okay until i add redirect('/blog/login') fuction into my code. then even if i had session cookie in my browser i get error about
TypeError: date.getTime is not a function. (In 'date.getTime()', 'date.getTime' is undefined)
at isWithinExpirationDate (:40:37)
at <anonymous> (:76:74)
at processTicksAndRejections (:12:39)
⨯ TypeError: date.getTime is not a function. (In 'date.getTime()', 'date.getTime' is undefined)
at isWithinExpirationDate (:40:37)
at <anonymous> (:76:74)
at processTicksAndRejections (:12:39)
TypeError: date.getTime is not a function. (In 'date.getTime()', 'date.getTime' is undefined)
at isWithinExpirationDate (:40:37)
at <anonymous> (:76:74)
at processTicksAndRejections (:12:39)
⨯ TypeError: date.getTime is not a function. (In 'date.getTime()', 'date.getTime' is undefined)
at isWithinExpirationDate (:40:37)
at <anonymous> (:76:74)
at processTicksAndRejections (:12:39)
here is my protected route code:
import { validateSession } from "@/auth"
import { redirect } from "next/navigation"

const Create = async () => {
const {user} = await validateSession()
if (!user) {
return redirect("/blog/login")
}

return (
<main className="min-h-screen relative z-20">Create</main>
)
}

export default Create
import { validateSession } from "@/auth"
import { redirect } from "next/navigation"

const Create = async () => {
const {user} = await validateSession()
if (!user) {
return redirect("/blog/login")
}

return (
<main className="min-h-screen relative z-20">Create</main>
)
}

export default Create
And thats my validateSession function.
export const validateSession = cache(async () => {
const sessionId = cookies().get(lucia.sessionCookieName)?.value ?? null;
if (!sessionId) {
return {
user: null,
session: null
}
}



const { user, session } = await lucia.validateSession(sessionId);
try {
if (session && session.fresh) {
const sessionCookie = lucia.createSessionCookie(session.id);
cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes);
}
if (!session) {
const sessionCookie = lucia.createBlankSessionCookie();
cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes);
}
} catch {
// Next.js throws error when attempting to set cookies when rendering page
}
return {user, session};
});
export const validateSession = cache(async () => {
const sessionId = cookies().get(lucia.sessionCookieName)?.value ?? null;
if (!sessionId) {
return {
user: null,
session: null
}
}



const { user, session } = await lucia.validateSession(sessionId);
try {
if (session && session.fresh) {
const sessionCookie = lucia.createSessionCookie(session.id);
cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes);
}
if (!session) {
const sessionCookie = lucia.createBlankSessionCookie();
cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes);
}
} catch {
// Next.js throws error when attempting to set cookies when rendering page
}
return {user, session};
});
1 replies