Cannot create admin user

default discord avatar
Nball
9 months ago
42

1. Got locked out of cloud project admin account, unclear why, with UI showing "Unauthorized, you must be logged in to make this request." with log out button.


2. Email password reset not working - is there additional configuration needed for this feature on cloud? This hasn't worked for me across a few projects now.


3. Runtime logs show

ERROR (payload): APIError: No User


4. DB shows user however loginAttmepts are 0


5. Tried deleting the admin user in the DB to force reset, cleared cookies, etc


6. Created new user with same email as previous via /admin/login


7. Return to step 1



Repo is public:

https://github.com/ballermatic/gb-cms

payload.config.ts
import dotenv from 'dotenv'
import path from 'path'
import { buildConfig } from 'payload/config'

import { Pages } from './collections/Pages'
import { Users } from './collections/Users'

dotenv.config()

export default buildConfig({
  admin: { user: Users.slug }, // added this in testing, no effect
  collections: [Pages, Users],
  cors: [process.env.PAYLOAD_PUBLIC_SERVER_URL, process.env.PAYLOAD_PUBLIC_SITE_URL],
  csrf: [process.env.PAYLOAD_PUBLIC_SERVER_URL, process.env.PAYLOAD_PUBLIC_SITE_URL],
  typescript: {
    outputFile: path.resolve(__dirname, 'payload-types.ts'),
  },
})
  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    @Nball it sounds like your cookie settings are incorrect, likely due to your env not loading properly. Double check your import statement for

    dotenv

    . I think the proper way to import this module using ES6 syntax is

    import {} from 'dotenv/config';

    although I typically opt for CommonJS like this

    require('dotenv').config()
  • default discord avatar
    Nball
    9 months ago

    Aha, will do!



    @jacobsfletch I tried this, builds and deploys, but get an error when visiting /admin. I was attempting to use this approach

    https://discord.com/channels/967097582721572934/1098088422553440256

    which had worked for me earlier.



    Uncaught TypeError: n(...).config is not a function

    in browser console after successful deployment.

  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    Hmmmm strange error



    But I do think another problem is that your importing the env

    after

    your collections

  • default discord avatar
    Nball
    9 months ago

    Haha yeah, today is my auth/access/cors/csrf deep dive.



    OH!



    I hadn't considered that … at all

  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    So it a fun day for you sounds like haha



    Yea your cookie domain in your users collections probably is setting an undefined property

  • default discord avatar
    Nball
    9 months ago

    Thank you, and the whole team, for being here for us n00bs while we learn!

  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    We're all learning, it's a win-win πŸ‘



    Let me know if you still have any troubles here

  • default discord avatar
    Nball
    9 months ago

    Weird, same issue. Checking ENV on cloud but I am 99% certain they're correct.





    ENV are correct. COOKIE_DOMAIN is set to localhost, that shouldn't affect my ability to access the cloud admin, or should it?

    image.png
  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    oh yea

    COOKIE_DOMAIN

    needs to be the live domain, just like

    cors

    and

    csrf


    because otherwise your cookie will not attach to your browser

  • default discord avatar
    Nball
    9 months ago

    How does one test preview etc locally with cloud?



    localhost:3000 <--> payloadcms.app kinda thing



    Where local would be next.js with the intent to deploy to vercel, for example

  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    You could run the CMS locally alongside your Next.js app



    While connecting to the same Mongo instance, if needed

  • default discord avatar
    Nball
    9 months ago

    Ah yes, I was doing that earlier and it worked well. Huh. Definitely learning here. Ok, thank you. I have somewhat of an idea how to make the preview example work now.



    Should cookie domain be the cms or the front end?



    Not seeing documentation on that, unless it's in the JWT library?



    https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#third-party_cookies


    And here I thought I had a handle on cookies this whole time, sigh



    The preview example is what is getting me turned around, because the cookie domain is the same for the front and back ends πŸ˜„

  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    The cookie domain is the domain of any site you wish to allow cookies for

  • default discord avatar
    Nball
    9 months ago

    Can that be an array like cors or csrf?

  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    This excludes the protocol, i.e.

    payloadcms.com

    would work for a

    local.payloadcms.com

    front-end and a

    cms.local.payloadcms.com

    backend



    It cannot be an array, without looking the MDN docs there should indicate that

  • default discord avatar
    Nball
    9 months ago

    BE and FE will have different domains

  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    Then you won't be able to take advantage of the security that the cookie domain provides



    Just use

    auth: true
  • default discord avatar
    Nball
    9 months ago

    Aha, ok.



    Thank you again!

  • discord user avatar
    jacobsfletch
    Payload Team
    9 months ago

    No problem!

  • default discord avatar
    Nball
    9 months ago

    @jacobsfletch I was incorrect, my plan is to use a single domain. For example, CMS =

    https://edit.gravybo.at

    (currently set up as a CNAME in the Vercel DNS), dig shows it's functioning, however I am getting an SSL error

    SSL_ERROR_NO_CYPHER_OVERLAP

    where the parent domain SSL is fine, as is the destination value:

    https://gb.payloadcms.app


    I feel like there should be a separate thread.

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.