Adesh
Adesh
Explore posts from servers
DTDrizzle Team
Created by Adesh on 4/2/2025 in #help
Package pg can't be external
I am creating a turborepo with two next.js apps, and a db package that uses drizzle-orm, and api package that uses trpc. I have things set up according to the docs, but when I run the web app (pnpm run dev), it error out with the following error:
[email protected]/node_modules/drizzle-orm/node-postgres
Package pg can't be external
│ The request pg matches serverExternalPackages (or the defa
│ ult list).
│ The request could not be resolved by Node.js from the proj
│ ect directory.
│ Packages that should be external need to be installed in t
│ he project directory, so they can be resolved from the out
│ put files.
│ Try to install it into the project directory by running np
│ m install pg from the project directory.
[email protected]/node_modules/drizzle-orm/node-postgres
Package pg can't be external
│ The request pg matches serverExternalPackages (or the defa
│ ult list).
│ The request could not be resolved by Node.js from the proj
│ ect directory.
│ Packages that should be external need to be installed in t
│ he project directory, so they can be resolved from the out
│ put files.
│ Try to install it into the project directory by running np
│ m install pg from the project directory.
I have created a repo for the same, https://github.com/adeshgg/ultimate-monorepo/tree/feat/auth-in-api I am new to turborepo, Is there something that I am missing here?
3 replies
HHono
Created by Adesh on 1/22/2025 in #help
Get `auth` session when API endpoint is called from a server component
import { Hono } from 'hono'
import { verifyAuth } from '@hono/auth-js'
import { zValidator } from '@hono/zod-validator'
import { db } from '@/db'
import { insertPostSchema, posts } from '@/db/schema'
import { auth } from '@/auth'

const app = new Hono()
// Protect API for authenticated users only
.get('/', async (c) => {
// Get the session manually instead of using middleware
const session = await auth()

// Check authentication
if (!session?.user) {
return c.json({ error: 'Unauthorized' }, 401)
}

const posts = await db.query.posts.findMany({})
return c.json(posts)
})
import { Hono } from 'hono'
import { verifyAuth } from '@hono/auth-js'
import { zValidator } from '@hono/zod-validator'
import { db } from '@/db'
import { insertPostSchema, posts } from '@/db/schema'
import { auth } from '@/auth'

const app = new Hono()
// Protect API for authenticated users only
.get('/', async (c) => {
// Get the session manually instead of using middleware
const session = await auth()

// Check authentication
if (!session?.user) {
return c.json({ error: 'Unauthorized' }, 401)
}

const posts = await db.query.posts.findMany({})
return c.json(posts)
})
The session is undefined when the route is called from the server component, but I get the value when I call it from the client component
77 replies