Skip to content

fronteggNextJs middleware seems to be broken #27

@scech

Description

@scech

Hi, I found an issue when trying to setup Frontegg middleware with Next.js as described in the documentation. There seems to be a problem when checking whether given route is frontegg public route here, but only when isFronteggPublicRoute function is called from fronteggNextJs middleware. I also tried to setup express app with frontegg middleware and it works correctly.

Actual behaviour

  • following API requests sent from login screen fail with status code 401
    • /api/frontegg/metadata?entityName=saml
    • /api/frontegg/identity/resources/sso/v1
    • /api/frontegg/identity/resources/configurations/v1/public
  • user is not able to log in to the app using login form

Expected behaviour

  • requests to public API mentioned above succeed with status code 200
  • login flow works correctly

For now, we are using following workaround to make fronteggNextJs middleware work:

export default (req: NextApiRequest, res: NextApiResponse) => {

  // we had to remove `/api/frontegg` part
  // of `req.url` to make it work correctly
  req.url = req.url.replace('/api/frontegg', '')
  
  return fronteggNextJs({
    clientId: process.env.FRONTEGG_CLIENT_ID,
    apiKey: process.env.FRONTEGG_API_KEY,
    authMiddleware: withAuthentication(),
    contextResolver: async (req) => {
      return {
        tenantId: req.user ? req.user.tenantId : '',
        userId: req.user ? req.user.id : '',
        permissions: [FronteggPermissions.All],
      }
    },
  })(req, res)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions