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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ NEXTAUTH_URL=http://localhost:3000
NEXT_PUBLIC_BASE_URL=http://localhost:3000
NEXT_PUBLIC_MARKETING_URL=http://localhost:3000

# Domain where Papermark is being server
DOMAIN="papermark.io"

# These variables are from Vercel Storage Postgres
POSTGRES_PRISMA_URL=
POSTGRES_PRISMA_URL_NON_POOLING=
Expand All @@ -16,6 +19,8 @@ GOOGLE_CLIENT_SECRET=

# This variable is from Resend to send emails
RESEND_API_KEY=
RESEND_SENDER_SYSTEM=""
RESEND_SENDER_VERIFY=""

# This variable is from Tinybird to publish and read event data
TINYBIRD_TOKEN=
Expand Down
8 changes: 4 additions & 4 deletions lib/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ export const sendEmail = async ({
from: marketing
? "Marc from Papermark <[email protected]>"
: system
? "Papermark <[email protected]>"
? process.env.RESEND_SENDER_SYSTEM || "Papermark <[email protected]>"
: verify
? "Papermark <[email protected]>"
? process.env.RESEND_SENDER_VERIFY || "Papermark <[email protected]>"
: !!scheduledAt
? "Marc Seitz <[email protected]>"
: "Marc from Papermark <[email protected]>",
? process.env.RESEND_SENDER_SYSTEM || "Marc Seitz <[email protected]>"
: process.env.RESEND_SENDER_SYSTEM || "Marc from Papermark <[email protected]>",
to: test ? "[email protected]" : to,
cc: cc,
replyTo: marketing ? "[email protected]" : undefined,
Expand Down
2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default async function middleware(req: NextRequest, ev: NextFetchEvent) {
(process.env.NODE_ENV !== "development" &&
!(
host?.includes("localhost") ||
host?.includes("papermark.io") ||
host?.includes(process.env.DOMAIN || "papermark.io") ||
host?.endsWith(".vercel.app")
))
) {
Expand Down
4 changes: 2 additions & 2 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import prisma from "@/lib/prisma";
import { CreateUserEmailProps, CustomUser } from "@/lib/types";
import { generateChecksum } from "@/lib/utils/generate-checksum";

const VERCEL_DEPLOYMENT = !!process.env.VERCEL_URL;
const VERCEL_DEPLOYMENT = (!!process.env.VERCEL_URL || !!process.env.DOMAIN);

// This function can run for a maximum of 180 seconds
export const config = {
Expand Down Expand Up @@ -88,7 +88,7 @@ export const authOptions: NextAuthOptions = {
sameSite: "lax",
path: "/",
// When working on localhost, the cookie domain must be omitted entirely (https://stackoverflow.com/a/1188145)
domain: VERCEL_DEPLOYMENT ? ".papermark.io" : undefined,
// TODO: Verify if we really need to set a domain
secure: VERCEL_DEPLOYMENT,
},
},
Expand Down