Connect the auth api to express

hello friends !
my name is Asi im working as web developer, and im trying to to use the auth0 roles and premissions, im trying to implement it on my project, im working as client Angular and as back-end my server is express.
and i dont understand how to use it well in order to use the roles and presmissions,
now im trying to implement the code from the website docomunation and it dosent work for me.

maybe becuase im using ES-6 and it want only the old way… not sure
maybe someone here can explain me how to implement that auth0 on my server express?
this is my code for now -

import { auth, requiresAuth } from "express-openid-connect";

const config = {
  authRequired: false,
  auth0Logout: true,
  baseURL: "http://localhost:3000",
  clientID: "JbmkcjuyYCurzhyQjny3dkxb3YroMPXX",
  issuerBaseURL: "http://localhost:4200",
  secret: "45donIsBL8xBvBCT1mb49-O0DA5Wzt1hjfYfxpChkloQWIDETGbEVpSfIl8Md6PR",
};

// The `auth` router attaches /login, /logout
// and /callback routes to the baseURL
app.use(auth(config));

// req.oidc.isAuthenticated is provided from the auth router
app.get("/", (req, res) => {
  res.send(req.oidc.isAuthenticated() ? "Logged in" : "Logged out");
});

// The /profile route will show the user profile as JSON
app.get("/profile", requiresAuth(), (req, res) => {
  res.send(JSON.stringify(req.oidc.user, null, 2));
});

it gives me error -

SyntaxError: Named export 'requiresAuth' not found. The requested module 'express-openid-connect' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'express-openid-connect';
const { auth, requiresAuth } = pkg;

if someone can help me ill be very greatfull !!

Hi @asi,

Have you tried using the method described in the error message, i.e.

import pkg from 'express-openid-connect';

This may help explain it:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.