The combination of NextAuth.js and Auth0 seems to be causing an issue with offline_access breaking

I am currently integrating next-auth with the Auth0 provider into an existing application. Everything is functioning properly, however, when attempting to include the offline_access scope in order to retrieve a refresh token, the application randomly crashes after a few seconds:

https://next-auth.js.org/warnings#no_secret
[next-auth][error][JWT_SESSION_ERROR]
https://next-auth.js.org/errors#jwt_session_error decryption operation failed {
  message: 'decryption operation failed',
  stack: 'JWEDecryptionFailed: decryption operation failed\n' +
    '    at gcmDecrypt (my_path/node_modules/jose/dist/node/cjs/runtime/decrypt.js:67:15)\n' +
    '    at decrypt (my_path/node_modules/jose/dist/node/cjs/runtime/decrypt.js:92:20)\n' +
    '    at flattenedDecrypt (my_path/node_modules/jose/dist/node/cjs/jwe/flattened/decrypt.js:119:52)\n' +
    '    at runMicrotasks (<anonymous>)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:95:5)\n' +
    '    at async compactDecrypt (my_path/node_modules/jose/dist/node/cjs/jwe/compact/decrypt.js:18:23)\n' +
    '    at async jwtDecrypt (my_path/node_modules/jose/dist/node/cjs/jwt/decrypt.js:8:23)\n' +
    '    at async Object.decode (my_path/node_modules/next-auth/jwt/index.js:62:7)\n' +
    '    at async Object.session (my_path/node_modules/next-auth/core/routes/session.js:41:28)\n' +
    '    at async NextAuthHandler (my_path/node_modules/next-auth/core/index.js:96:27)\n' +
    '    at async NextAuthNextHandler (my_path/node_modules/next-auth/next/index.js:20:19)\n' +
    '    at async my_path/node_modules/next-auth/next/index.js:56:32\n' +
    '    at async apiResolver (my_path/node_modules/next/dist/next-server/server/api-utils.js:8:1)\n' +
    '    at async DevServer.handleApiRequest (my_path/node_modules/next/dist/next-server/server/next-server.js:64:462)\n' +
    '    at async Object.fn (my_path/node_modules/next/dist/next-server/server/next-server.js:56:492)\n' +
    '    at async Router.execute (my_path/node_modules/next/dist/next-server/server/router.js:23:67)',
  name: 'JWEDecryptionFailed'
}

At the moment, I am simply adjusting the scopes and not actively using the refresh token. Returning to the default scopes resolves the issue.

Below is the code snippet:

export default NextAuth({
    // Configure one or more authentication providers
    providers: [
      Auth0Provider({
        clientId: CLIENT_ID,
        clientSecret: CLIENT_SECRET,
        issuer: ISSUER,
        idToken: true,
        // authorization: {params: {scope: 'openid email profile offline_access'}},
      }),
    ],
    callbacks: {
      async signIn({profile}) {
        // Sentry.setUser(...)
        return true
      },
      async redirect({baseUrl}) {
        return baseUrl
      },
      async jwt({token, account, profile}) {
        if (account) {
          token.accessToken = account.id_token
        }
        if (profile) {
          token.profile = profile['https://my-company-oauth-profile-path/']
        }
  
        return token
      },
      async session({session, token}) {
        session.accessToken = token.accessToken
        session.profile = token.profile
        return session
      },
    },
    pages: {
      signIn: '/auth/signin',
    },
    debug: true,
})

The next-auth version I am using is "4.1.2".

Answer №1

If you're facing a similar issue, take note of this:

https://next-auth.js.org/configuration/options#secret

It's crucial to define a value for the secret option, as the default behavior is unreliable. Failure to provide a secret in production will result in an error.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Every time I attempt to submit data, I encounter a 404 error with AXIOS

Struggling to figure out why I keep encountering an error when trying to send form data from my website to the database using axios? Despite attempting various solutions, the problem persists. Although I can successfully retrieve manually entered data from ...

Challenges with implementing a jQuery sortable table in Laravel

I've integrated tableclothjs and Twitter Bootstrap into my project, but the sortable headers are not appearing as expected. I've checked the JavaScript console for any errors or warnings, but there doesn't seem to be any issue indicated. Wh ...

Attaching a buoyant div to the precise location of a different element

I have a unordered list (ul) with individual list items (li) that are displayed within a scrollable container. This means that only 8 list items are visible at a time, but you can scroll through them to see the others. Each list item (li) has an "edit" b ...

What are your thoughts on this method for preventing scrolling?

Is there a way to prevent scrolling of the underlying content on a webpage when a modal is displayed? I found this code snippet that achieves that. (http://jsfiddle.net/77P2e/) var $window = $(window), previousScrollTop = 0, scrollLock = false; $window.s ...

I am having trouble recognizing the final character within a string

Starting to learn Javascript and working on a basic calculator. My goal is to track the last character entered in the calculator display to prevent double symbols like (++, ./, *-, etc.) Since the input comes as a string, I've attempted using the met ...

Navigating through intricate JavaScript object

I need help figuring out how to access the "description" property of a JSON object I received from an API endpoint. The object looks like this: - "description" : "Dorian Market 1"? let markets = { "result":[ { "townId" : "MEBD", "stor ...

Refreshing CommonJS modules by reloading or reinitializing them

It is well known that CommonJS modules are designed to load only once. Imagine we have a Single Page application with hash-based navigation; when we go back to a page that has already been loaded, the code does not run again because it has already been loa ...

Alternate the color over time using CSS

Is there a way to dynamically change the color of a div from black to white every two seconds, and then from white to black, continuously toggling as long as the div is visible? Essentially, I want the div to only be displayed when a user clicks and drag ...

Failed verification of C-Lang in React-Hardware/Particle

Currently, I am utilizing React, React Hardware ([https://github.com/iamdustan/react-hardware/]), and Johnny-Five along with the Particle Photon. The error stack displayed below is what pops up when executing my lib/app.js file: # Fatal error in ../deps/v ...

ng grid shift select issue mistakenly selects extra rows

Take a look at my plunker here: link var app = angular.module('app', []); // encountering a silly error that prevents me from pasting the entire code, please refer to the plunker for details To replicate the issue: Click on the first row with ...

Use AJAX request to download file and handle errors in case the file is not found or cannot be downloaded

Trying to implement an ajax request for downloading a file. Here's the code snippet: const downloadFile = (element) => { $.ajax({ url: element.id, type: 'GET', success: (result) => { window.lo ...

The AJAX Request has indicated that the entity provided is not in an accurate 'application/json' format. It seems to be missing or empty, leading to an error with a code of '400'

While attempting to create an AJAX request to submit users to an external API, I faced a problem that is hindering my progress. Since I'm more familiar with PHP than JS, I saw this as an opportunity to expand my knowledge in JavaScript. The approach ...

Having trouble signing out in Nextjs?

As a newcomer to Reactjs and Nextjs, I am currently working on developing an admin panel. To handle the login functionality, I have implemented the following code in my index.js/login page using session storage: const data = { name: email, password: pa ...

The next.js Incremental Static Regeneration feature can optimize response times to as fast as

We have hit a wall in terms of build times in our CI/CD process. With 9k pre-rendered pages and the switch to ISR, we are now able to update and generate the less relevant pages on-the-fly. During a small load test, we noticed a significant drop in the ov ...

Creating a classification for a higher order function

In the code snippet below, I have a controller that acts as a higher order method: const CourseController = { createCourse: ({ CourseService }) => async (httpRequest) => { const course = await CourseService.doCreateCourse(httpRequest. ...

Fixing blurry text on canvas caused by Arbor.js mouse event issues

Currently, I am utilizing arborjs in my project. The text within the canvas is created using fillText in html5. While everything functions correctly on a Retina display MacBook, the text appears blurry. To address this, I applied the following solution: v ...

Automatically, the "ng-hide" class gets added despite using the correct syntax for ng-show

I am trying to dynamically show/hide a tr tag within a table based on the value of a scope variable in the controller. Despite writing the code correctly, I am facing an issue where the "ng-hide" class is automatically added to the tr tag every time it is ...

Cordova experiencing difficulty loading platform API

Lately, I've been facing a persistent issue with Cordova. Whenever I try to run it in the browser, an error pops up saying that the browser is not added as a platform. Even when I attempt to add the browser as a platform, another error occurs stating ...

Issue with Global Variable Not Being Updated in Javascript

In my code snippet below, I am struggling to update a global variable within a callback function. function FunctionOne() { var result = ""; for (var i = 0; i < 10; i++) { AjaxFunction(function (data) { result += data; ...

What are some ways to condense this Angular/TS code for improved performance and readability?

I am in need of assistance with refactoring a method called getBaseUrl(). This method assigns a specified string value to this.baseURL based on the input serviceType. getBaseUrl(serviceType: string, network?: string) { // Method logic to determine base ...