create-t3-turbo monorepo: How to access user session to packages/db?

I would like to access some props from user's session to prisma middleware i.e. in below example: I would like to get contextLanguage from user's session (nextauth). adding @acme/auth as a dependency to @acme/db package, may create circular dependency? https://www.prisma.io/docs/concepts/components/prisma-client/middleware/session-data-middleware
const prisma = new PrismaClient()

const contextLanguage = 'en-us' // Session state

prisma.$use(async (params, next) => {
if (params.model == 'Post' && params.action == 'create') {
params.args.data.language = contextLanguage
}

return next(params)
})

const create = await prisma.post.create({
data: {
title: 'My post in English',
},
})
const prisma = new PrismaClient()

const contextLanguage = 'en-us' // Session state

prisma.$use(async (params, next) => {
if (params.model == 'Post' && params.action == 'create') {
params.args.data.language = contextLanguage
}

return next(params)
})

const create = await prisma.post.create({
data: {
title: 'My post in English',
},
})
Prisma
Middleware sample: session data (Reference)
How to use middleware to set the value taken from session state.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server