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.

/admin/login doesnt function as expected

default discord avatar
johnmontg2 years ago
25

Hey all, were facing some issues with deploying the payload-next-demo app. We only face this when deploying with SST.



Essentially, the /api/users/login is route is not erroring (no log output), but we receive a 200 ok response with no data. We are unable to reproduce this locally, but wondering if anyone who is slightly more familiar with the codebase can help. I have also tried deploying a basic next app and attaching payload-next myself, which yields the same results.



We see no client side failure, but nothing actually happens, you hit login, which is followed by a 200 with no data, and you are not logged in. We do not see any issues at other API routes, like /api/users/me, or /api/users/init.



Have dug some more into this. We are seeing a status 200 returned, with no error message, and no payload. I have attempted invoking /forgot-password instead, and there we see a 500, which, has a key difference of returning our stack and an error message, rather than the unexpected 200 without data.



narrowed it down some more, on successful post requests, we see no data coming back to us



futher narrowed down, the 'body' is not making it to the lambda, nor is the expected data under any of the expected fields - this is fixed with bodyparser set to fasle



It appears

'payload/dist/auth/operations/login'

is returning with res.status somewhere, with a 200. Any help is appreciated



Added a beforeOp and beforeLogin Hook to trace. beforeOp logs are successfull, but no beforeLogin hook gets run. Narrows down the issue to this section (

https://github.com/payloadcms/payload/blob/master/src/auth/operations/login.ts#L56-L130

)



Seems like, from a walkthrough it can be narrowed down to either: lines 96-98 or 126



Seems like we can rule out line 126, as it seems we should have guarenteed ourselves an auth error before that point on line 102 (purposely using wrong creds) - seems reasonable to assume its an issue somewhere in the auth function



one possible spot: this should probably use Buffer and not the string of password if im not mistaken?

https://github.com/payloadcms/payload/blob/master/src/auth/strategies/local/authenticate.ts#L23

- not sure this is our root cause though



possibly narrowed down more to an issue where lambda isnt allowing a proper connection to mongo - seems like it works on startup but is somehow intermittently failing with findOne, but no logging



strange, simply calling

console.log(await Model.findOne({ email }));

is causing this issue it seems. When this is executed in the hook, the lambda instantley ends with a 200



bumping this as were not seeing anything coming through still, could this be to do with the config of the mongoose client?

  • default discord avatar
    notchr2 years ago
    @844209275089453076

    When you say that you click login, do you mean from the Payload admin panel?



    Where does the login "failure" occur

  • default discord avatar
    johnmontg2 years ago

    Yea



    The login doesn’t actually “fail” the request is returned with 200, but with no response



    (Which, is basically a no op on the admin panel and just stalls)



    Notable, in the lambda logs we see no error message either, we added some custom logging and saw that it seems to end directly after the FindOne



    Repro steps are: clone the demo, yarn sst create and then yarn sst deploy

  • default discord avatar
    notchr2 years ago
    @858693520012476436

    This person has been stuck for a bit, any ideas on this? You've worked with serverless before, right?



    Actually, I think paul only has deployed on Vercel



    @281120856527077378

    Any ideas on this one? 😄



    @844209275089453076

    On a side not while we are waiting for some folks with more knowledge



    Have you tried hitting the API instead of logging in, as a test?



    Via like postman, etc

  • default discord avatar
    johnmontg2 years ago

    Yes

  • default discord avatar
    paulpopus2 years ago

    Yeah I only deployed on vercel and migrated that project away from serverless in the end actually

  • default discord avatar
    johnmontg2 years ago

    No difference



    Aws > vercel sorry not sorry



    :payloadlove:

    I’ve isolated this all the way down using a before op hook, and running a direct Model.findOne on a hardcoded email

  • default discord avatar
    paulpopus2 years ago

    same thing under the hood...the whole internet is 😭

  • default discord avatar
    notchr2 years ago

    IMO REST + selfhost is best



    only because i never run into any complicated issues hehe



    @844209275089453076

    I feel like the findOne discovery is a symptom of the issue but not the cause



    But to get no response data back is super weird



    especially if the requests come back 200



    @844209275089453076

    Do you know if there were any oddities when configuring your payload server settings, etc



    CORS, CSRF, anything odd?



    Also, if you add a standalone route in server.ts, just a base express route, can you hit that?



    If not then I think that is telling

  • default discord avatar
    johnmontg2 years ago

    This is from the lambda to be clear



    It kills the lambda somehow



    It’s incredibly odd



    I’ve engaged mongoose and I’ll try engaging aws support



    💪

  • default discord avatar
    notchr2 years ago

    And the Lambda doesn't throw any errors / log?

  • default discord avatar
    johnmontg2 years ago

    No lol



    I’ve basically got uh



    console.log(“blah”)


    Model.findOne({email:”test@test.com”});


    Console.log(“I got here”)



    And I get



    blah


    END REQUEST UUID



    Sorry for the horrific formatting, let me like the mongoose discussion incase it’s from there



    https://github.com/Automattic/mongoose/discussions/13852

    To be clear, I’m not clear on if this was a payload issue but was looking for help it’s sipoer weird

  • default discord avatar
    notchr2 years ago

    Is the mongodb self hosted or through atlas?

  • default discord avatar
    johnmontg2 years ago

    Even inside a try catch btw



    Atlas serverless



    Another point tho- it’s able to create the collections

  • default discord avatar
    notchr2 years ago

    Oh it doesnt hit the catch?



    @844209275089453076

    Can we check out how your payload config is setup?

  • default discord avatar
    johnmontg2 years ago

    The user has full admin perms



    Also, had it wrapped in try catch and saw nothing!



    On another note the lack of logging has been a bit frustrating tbh- I’ll have to get approval from my company before working on anything FOSS but once I do I’ll look at raising some PRs



    Yh- but am at work for time being



    Exactly



    ok so, i know this isnt great

    MONGODB_URI=mongodb+srv://USERNAME:PASSWORD@serverlessinstance2.ozlmxxx.mongodb.net/?retryWrites=true&w=majority
    PAYLOAD_SECRET=YOUR_SECRET_HERE
    PAYLOAD_CONFIG_PATH=dist/payload.config.js
    NEXT_PUBLIC_APP_URL=https://xxxx.cloudfront.net
    PAYLOAD_PUBLIC_CMS_URL=https://xxxx.cloudfront.net
    S3_ACCESS_KEY_ID=
    S3_SECRET_ACCESS_KEY=
    S3_REGION=
    NEXT_PUBLIC_S3_ENDPOINT=
    NEXT_PUBLIC_S3_BUCKET=


    but this

  • default discord avatar
    sisidotdev2 years ago

    I gave PayloadCMS 2.0 w/ Postgres using NextJS on SST a shot. Unfortunately the same error occurs even with Postgres. I was able to create the first user, but I can't Login.

  • default discord avatar
    johnmontg2 years ago

    Super weird, is that still using mongoose somewhrrr then?

  • discord user avatar
    denolfe
    2 years ago

    No, Mongoose is isolated to the db-mongodb adapter now. There isn't anything in core using it.



    All this being said, we have not attempted to look into what is needed for SST support.

  • default discord avatar
    dreamylucid2 years ago

    It has nothing to do with the database of choice. It seems like a re-direction does not happen after the login/first-registration

  • discord user avatar
    denolfe
    2 years ago

    I can't say we've put any effort into supporting SST at this point. Pretty niche.

  • default discord avatar
    sisidotdev2 years ago

    It's niche until you migrate to nextjs. Vercel is great, but not always the solution from a legal point of view.

  • default discord avatar
    david_mcbacon2 years ago

    hey guys, I'm having the same problem with PayloadCMS 2.0 (payload-next monorepo setup) & SST. I've tried postgres (supabase) and mongodb (atlas) and in both cases I wasn't able to log in, while recieveing reponse code 200 :/



    @838356081943773204

    , just wondering did you try postgres using SST RDS serverless cluster?

  • default discord avatar
    dreamylucid2 years ago

    Able to share what is the legal point of view for using Vercel?



    This is the exact same setup I POC-ed for as well. Same result

  • default discord avatar
    sisidotdev2 years ago

    Sorry for the late reply. Legal as in being GDPR compliant and making really sure, that the PII data is not send across borders.

  • default discord avatar
    dreamylucid2 years ago

    Oh I see



    Thanks for the explanation

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.