Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Reinstall node_modules on payload latest runs into middleware issue again

default discord avatar
notchr2 years ago
19

Hey all,



Just updated payload and reinstalled my node_modules folder. Noticing I'm hitting the middleware issue with payload.authenticate again. Also can confirm payload.init is before the auth call. What could be causing this?



Thank you!



@364124941832159242



OK SO



This is weird



it works if..



payload.init({
    secret: process.env.PAYLOAD_SECRET,
    mongoURL: process.env.MONGODB_URI,
    express: app,
    onInit: () => {
      payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
      router.use(payload.authenticate); // OK
    },
  });
  
  // router.use(payload.authenticate);  (undefined)


but I doubt it's ok to call .use onInit ?



@1032341301619871785

ever seen this before?



Issue is currently blocking me at work :X

  • discord user avatar
    jmikrut
    2 years ago

    it's fine to do that in

    onInit

    for sure but the real question is, what has changed?

  • default discord avatar
    notchr2 years ago

    Exactly, nothing has 😮 (at least in my code)



    We tried to install the lexical plugin earlier today

  • discord user avatar
    jmikrut
    2 years ago

    can you show me your full server file?

  • default discord avatar
    notchr2 years ago

    And I then removed it



    sure thing



    https://gist.github.com/notchris/93c78db75e4cf8e9388c1b63ef8408e8

    Had to make a gist, dont have nitro on this work discord



    Also, everything works with the payload.authenticate inside the onInit function



    Otherwise, outside, it is undefined (even after init)

  • discord user avatar
    jmikrut
    2 years ago

    well i want to see what

    doesn't

    work



    where did you have it when it did not work?

  • default discord avatar
    notchr2 years ago

    ah here



    payload.init({
        secret: process.env.PAYLOAD_SECRET,
        mongoURL: process.env.MONGODB_URI,
        express: app,
        onInit: () => {
          payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
          router.use(payload.authenticate); // OK
        },
      });
      
      // router.use(payload.authenticate);  (undefined)


    payload.authenticate is undefined there



    if uncommented

  • discord user avatar
    jmikrut
    2 years ago

    yea



    so this is because you are not awaiting

    payload.init

    it's an async call

  • default discord avatar
    notchr2 years ago

    😮



    How did it work prior

  • discord user avatar
    jmikrut
    2 years ago

    it is probably just up to the luck of the draw



    sometimes it works, sometimes it doesn't depending on how fast your code executes payload.init

  • default discord avatar
    notchr2 years ago

    omg

  • discord user avatar
    jmikrut
    2 years ago

    maybe a dependency updated that slowed down mongo connection or something, or schema creation, or graphql, etc

  • default discord avatar
    notchr2 years ago

    its in the docs too



    how did i miss this?

  • discord user avatar
    jmikrut
    2 years ago

    no worries

  • default discord avatar
    notchr2 years ago

    Was it always wrapped in a func

  • discord user avatar
    jmikrut
    2 years ago

    well, that was one of the breaking changes in 1.6.0



    but it's been like that for over a month

  • default discord avatar
    notchr2 years ago

    ugh im such a dummy

  • discord user avatar
    jmikrut
    2 years ago

    maybe 2

  • default discord avatar
    notchr2 years ago

    One day im going to find a real bug that wasn't just me not reading correctly



    Thanks for your time man, my bad

  • discord user avatar
    jmikrut
    2 years ago

    no problem!!!



    happy to help

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.