rollbar / rollbar/rollbar-react

Next.js AppRoute Example: How can we log an error in the middleware

Open
#125 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Next.js
Dominant language
JavaScript
Stars
46
Forks
9
Avg merge
2d 56m
Merged PRs (30d)
4

Description

Hi, I tried the Next.js App Router example. (#122)

I modified the middleware to log error.

Before

https://github.com/rollbar/rollbar-react/blob/418412deae8ab0f5b733b7cab3c6d81bd5db7a9f/examples/nextjs-approuter/src/app/middleware.ts#L4-L8

After

export function middleware(request: NextRequest) {
  rollbar.configure({ payload: { context: request.nextUrl.pathname } });

  rollbar.error('error!', (err, response) => {
    // insufficient privileges: post_client_item scope is required but the access token only has post_server_item.
    console.log('error', err, response);
  });

  return NextResponse.next();
}

But as commented above, this causes insufficient privileges error.

If I change the server token to a client post token here:

https://github.com/rollbar/rollbar-react/blob/418412deae8ab0f5b733b7cab3c6d81bd5db7a9f/examples/nextjs-approuter/src/rollbar.ts#L15

The middleware can log the error.
But should I use the client post token in the middleware?

Is there a way to recommend?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with examples/nextjs-approuter/src/app/middleware.ts and examples/nextjs-approuter/src/rollbar.ts at the linked lines. Trace how the middleware token is configured and compare the permissions required by the attempted logging call. Done means the example or its documentation clearly recommends the appropriate token usage and explains the insufficient-privileges behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, typescript
Domain
documentation, security, web-dev
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.