Like what we’re doing? Star us on GitHub!

Using a custom domain to point to cloud run instance hosting payload server not allowing auth

andΞ | scalene
last month
26

Hey Payload team,



I'm currently hosting my payload server on a google cloud run instance, i am using firebase hosting to point a custom domain to the end point, upon login in with an admin account I get the error "Unauthorized, you must be logged in to make this request. You are not allowed to access this page".



When i use the direct url for the endpoint provided from google cloud run with the same payload admin account it works.



@allanc



My investigation so far... does the

serverURL

need to be the exact domain and not a hosted url? docs found here

https://payloadcms.com/docs/configuration/overview#using-environment-variables-in-your-config


@jmikrut hey sorry for the tag, just needed some help here since the threads going stale 🙂

  • jmikrut
    Payload Team
    last month

    yes, the serverURL needs to be the actual URL (with https) that you access the Payload admin with



    you should also be able to leave it undefined if you don't know the serverURL - BUT if you do leave it undefined, then you need to whitelist the domains you'll be using in the

    csrf

    property of the Payload config



    because we only accept auth cookies from either serverURL or explicitly whitelisted domains in csrf array



    for security reasons

  • andΞ | scalene
    last month

    cc: @allanc



    thank you and appreciate you getting to this question

  • MRL
    last month

    Thanks @jmikrut, that helped me out also.

  • jmikrut
    Payload Team
    last month

    of course! 💸

  • andΞ | scalene
    last month

    @jmikrut hey adding in the serverURL didn't work, do we have to add it both to

    serverURL

    and the

    csrf


    @MRL did it work for you?

  • MRL
    last month

    All I had to do was add the serverURL in and make sure that matches the URL where you are hosting the application.

  • andΞ | scalene
    last month

    do you know if it supports the subdomain



    or the actual base domain @MRL

  • MRL
    last month

    It supports subdomains. So if your url is

    https://cms.mywebsite.com

    then that is what you need to enter into the serverURL

  • andΞ | scalene
    last month

    ah thank you @MRL it still doesnt work for us - maybe it might be something to do with firebase hosting a cloud run instance

  • MRL
    last month

    Do you have the url set in the .env files?

  • andΞ | scalene
    last month

    yep - set in the .env files on cloud run

  • MRL
    last month

    I'm not super clued up on Firebase hosting but if you can access the logs when it is building, you should be able to see where the serverUrl is pointing to. Or you can check the browser console to see where the API calls are being made to

  • andΞ | scalene
    last month

    sweet, for now i just redirected it to the main url on the firebase hosting



    so atleast its friendly to remember



    that works for now



    @MRL thanks

  • MRL
    last month

    All good 🙂

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More