Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable login on selfhosted instances #1490

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zolfariot
Copy link

Allow the user to define a main custom domain for self-hosting, under the DOMAIN environment variable,
this custom domain will be recognized by the middleware when run in production (local, non vercel) mode.

Secure cookies are used when a custom domain is set, thus requiring papermark to be served on https.

Finally, sender addresses can be customized with the RESEND_SENDER_SYSTEM and RESEND_SENDER_VERIFY environment variables, to be able to deliver emails from domains allowed in the instance RESEND api key.

Fixes #1353

@zolfariot zolfariot requested a review from mfts as a code owner February 13, 2025 10:10
Copy link

vercel bot commented Feb 13, 2025

@zolfariot is attempting to deploy a commit to the mftsio Team on Vercel.

A member of the Team first needs to authorize it.

@zolfariot zolfariot changed the title Enable login on selfhosted instances fix: enable login on selfhosted instances Feb 13, 2025
@mpadronm90
Copy link

@zolfariot Adding your changes manually still having this issue:

Something I found is that the custom domain you set in these variables gets blocked.

NEXTAUTH_URL=http://localhost:3000
NEXT_PUBLIC_BASE_URL=http://localhost:3000

So weird!

@zolfariot
Copy link
Author

Hello, are you hosting on your server or deploying to your Vercel account? And do you have https enabled for your custom domain url?

I could not reproduce on a minimal production-like test:

Preparation:

  1. Deploy a fresh Debian 12 VPS
  2. Install certbot, postgres, nginx
  3. certbot: create a letsencrypt certificate for papermark.$YOUR_DOMAIN
  4. postgres: create a user papermark with password $DB_PASS
  5. postgres: create a db papermark owned by user papermark
  6. nginx: replace the location block in the default https server statement with:
location / {
    proxy_pass              http://localhost:3000;
    proxy_set_header        Host $host;
    proxy_set_header        Connection "Upgrade";
    proxy_set_header        Upgrade $http_upgrade;
}

Papermark setup

As unprivileged user

  1. Install node22 lts with nvm (https://nodejs.org/en/download)
  2. Clone PR
git clone -b fix/enable_login_selfhosted https://github.com/zolfariot/papermark
  1. Enter papermark and copy .env.example to .env, then modify only the following entries of .env (replacing $YOUR_DOMAIN, $DB_PASS and $YOUR_RESEND_API_KEY):
NEXTAUTH_URL=https://papermark.$YOUR_DOMAIN
NEXT_PUBLIC_BASE_URL=https://papermark.$YOUR_DOMAIN
DOMAIN=papermark.$YOUR_DOMAIN
POSTGRES_PRISMA_URL="postgres://papermark:$DB_PASS@localhost:5432/papermark"
POSTGRES_PRISMA_URL_NON_POOLING="postgres://papermark:$DB_PASS@localhost:5432/papermark"
RESEND_API_KEY=$YOUR_RESEND_API_KEY
RESEND_SENDER_SYSTEM="papermark@$YOUR_DOMAIN"
RESEND_SENDER_VERIFY="papermark@$YOUR_DOMAIN"
  1. Install and build papermark
npm i
npm run build 
  1. Run the server (eventually in a screen/tmux or as a systemd unit)
npm run start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to login on self hosted
2 participants