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!
@jmikrut
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 ?
@patrikkozak ever seen this before?
Issue is currently blocking me at work :X
it's fine to do that in
onInit
for sure but the real question is, what has changed?
Exactly, nothing has 😮 (at least in my code)
We tried to install the lexical plugin earlier today
can you show me your full server file?
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)
well i want to see what
doesn'twork
where did you have it when it did not work?
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
yea
so this is because you are not awaiting
payload.init
it's an async call
😮
How did it work prior
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
omg
maybe a dependency updated that slowed down mongo connection or something, or schema creation, or graphql, etc
its in the docs too
how did i miss this?
no worries
Was it always wrapped in a func
well, that was one of the breaking changes in 1.6.0
but it's been like that for over a month
ugh im such a dummy
maybe 2
One day im going to find a real bug that wasn't just me not reading correctly
Thanks for your time man, my bad
no problem!!!
happy to help
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.