-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
running the lib in nextJS middleware #6
Comments
Also running into this issue. @surmon-china any ideas how to fix? |
|
@surmon-china Here is the code:
|
Hi! @Ezall2001 @fbjork I think this issue has been fixed in v0.3.0 (please note there are some breaking change) |
@surmon-china I just tried it, but now I get a new error:
|
Try v0.4.0 (API key desensitization is no longer processed when an error occurs.) |
@surmon-china now I'm getting this error:
|
This looks like an axios request error caused by the runtime environment, can you provide your system info? ( |
@surmon-china here goes. Also note that I'm using the edge runtime with my Next.js project.
|
@surmon-china anything else I can share to help fix this? |
Describe the bug
I am getting:
error - (middleware)\node_modules\mongodb-data-api\dist\mongodb-data-api.esm.js (106:0) @ eval
error - error.toJSON is not a function
Reproduction
-> mongodbDataApi.ts
`
import { createMongoDBDataAPI } from 'mongodb-data-api'
const connectToMongoAPI = (collection: string) => {
if (
!process.env.MONGODB_API_URL ||
!process.env.MONGODB_API_KEY ||
!process.env.MONGODB_CLUSTER ||
!process.env.MONGODB_DB_NAME
)
return undefined
return createMongoDBDataAPI({
apiKey: process.env.MONGODB_API_KEY,
urlEndpoint: process.env.MONGODB_API_URL,
})
.$cluster(process.env.MONGODB_CLUSTER)
.$database(process.env.MONGODB_DB_NAME)
.$collection(collection)
}
export default connectToMongoAPI
`
-> middleware.ts
`
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { getToken } from 'next-auth/jwt'
import connectToMongoAPI from 'lib/mongodbDataApi'
export const middleware = async (req: NextRequest) => {
const session = await getToken({ req, secret: process.env.SECRET })
/// auth Layer
if (
!session &&
!(
req.nextUrl.pathname.startsWith('/auth/login') ||
req.nextUrl.pathname.startsWith('/api/auth')
)
)
return NextResponse.redirect(new URL('/auth/login', req.url))
/// role layer
const res = await connectToMongoAPI('Pages')?.find({ filter: {} })
console.log(res)
}
export const config = {
matcher: ['/((?!_next|favicon.ico).*)'],
}
`
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: