Skip to content

feat: new auth & payment system #1617

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

Merged
merged 38 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
67f84c6
feat: implement better-auth & portal.sh
nperez0111 Apr 18, 2025
5975ba9
chore: hoist prettier to top-level
nperez0111 Apr 22, 2025
af103ad
chore: fix generation
nperez0111 Apr 22, 2025
284d550
feat: implement email notifications and magic links
nperez0111 Apr 22, 2025
06e8a4d
feat: implement github sponsors fallback
nperez0111 Apr 23, 2025
d64c270
feat: use supabase or any PG db
nperez0111 Apr 24, 2025
81ea387
chore: update env file
nperez0111 Apr 25, 2025
14180f0
fix: auto-sign in after email verification
nperez0111 Apr 25, 2025
40dee60
fix: make it more sensible
nperez0111 Apr 25, 2025
3f1aaf8
fix: use sqlite locally for ease of use
nperez0111 Apr 28, 2025
c0fe375
chore: fix env vars
nperez0111 Apr 28, 2025
a579d5f
chore: update env vars
nperez0111 Apr 28, 2025
6a9698e
fix: better pricing page
nperez0111 Apr 28, 2025
b2a7bc5
chore: tweak css
nperez0111 Apr 29, 2025
e701ff9
feat: Sign-up/login flows & UI (#1652)
matthewlipski May 1, 2025
dcaed39
build: get the build working again
nperez0111 May 1, 2025
842ca7c
Added manage sub button to user dropdown
matthewlipski May 1, 2025
b560a05
Merge branch 'better-payments' of github.com:TypeCellOS/BlockNote int…
matthewlipski May 1, 2025
0b96e97
Fixed server errors not being communicated to users
matthewlipski May 1, 2025
c8352ab
fix: add callback
nperez0111 May 1, 2025
dea0b54
chore: wait for send
nperez0111 May 1, 2025
d4e783e
fix: try something different for sending mail
nperez0111 May 1, 2025
fb25777
fix: use correct SMTP_FROM
nperez0111 May 1, 2025
2166372
chore: explicitly add deps
nperez0111 May 1, 2025
e7b465c
fix: update the price-id
nperez0111 May 1, 2025
6522be5
fix: make link to sign-in page
nperez0111 May 2, 2025
753878d
fix: support magic and verify email for welcome emails
nperez0111 May 2, 2025
99fa736
refactor: update welcome email text
nperez0111 May 2, 2025
946f54e
chore: rename
nperez0111 May 6, 2025
bd51830
docs: add setup steps
nperez0111 May 6, 2025
ca8c886
feat: revamp to use email first login
nperez0111 May 6, 2025
e3b42d0
fix: rm dynamic
nperez0111 May 6, 2025
4039d3b
feat: handle all payments through the webhooks
nperez0111 May 6, 2025
f3dc8c8
Merge branch 'main' into better-payments
nperez0111 May 6, 2025
2bc646c
build: put back dynamic
nperez0111 May 6, 2025
7fcafe4
feat: add a thanks page
nperez0111 May 6, 2025
62e2de1
chore: update hanging "or"
nperez0111 May 7, 2025
7e8296d
chore: update spacing and wording
nperez0111 May 7, 2025
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
32 changes: 27 additions & 5 deletions docs/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
AUTH_SECRET= # Linux: `openssl rand -hex 32` or go to https://generate-secret.vercel.app/32

AUTH_GITHUB_ID=
AUTH_GITHUB_SECRET=
# Better Auth Deployed URL
BETTER_AUTH_URL=http://localhost:3000

# The SENTRY_AUTH_TOKEN variable is picked up by the Sentry Build Plugin.
# It's used for authentication when uploading source maps.
SENTRY_AUTH_TOKEN=
# ======= OPTIONAL =======

# # Polar Sandbox is used in dev mode: https://sandbox.polar.sh/
# # You may need to delete your user in their dashboard if you get a "cannot attach new external ID error"
# POLAR_ACCESS_TOKEN=
# POLAR_WEBHOOK_SECRET=

# # In production, we use postgres
# POSTGRES_URL=

# # Email
# SMTP_HOST=
# SMTP_USER=
# SMTP_PASS=
# SMTP_PORT=
# # Insecure if false, secure if any other value
# SMTP_SECURE=false

# # For GitHub Signin method
# AUTH_GITHUB_ID=
# AUTH_GITHUB_SECRET=

# # The SENTRY_AUTH_TOKEN variable is picked up by the Sentry Build Plugin.
# # It's used for authentication when uploading source maps.
# SENTRY_AUTH_TOKEN=
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ next-env.d.ts

# Sentry Config File
.env.sentry-build-plugin
*.db
99 changes: 99 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Website Development

To get started with development of the website, you can follow these steps:

1. Initialize the DB

If you haven't already, you can initialize the database with the following command:

```bash
cd docs && pnpm run init-db
```

This will initialize an SQLite database at `./docs/sqlite.db`.

2. Setup environment variables

Copy the `.env.example` file to `.env.local` and set the environment variables.

```bash
cp .env.example .env.local
```

If you want to test logging in, or payments see more information below [in the environment variables section](#environment-variables).

3. Start the development server

```bash
cd docs && pnpm run dev
```

This will start the development server on port 3000.

## Environment Variables

### Logging in

To test logging in, you can set the following environment variables:

```bash
AUTH_SECRET=test
# Github OAuth optionally
AUTH_GITHUB_ID=test
AUTH_GITHUB_SECRET=test
```

Note: the GITHUB_ID and GITHUB_SECRET are optional, but if you want to test logging in with Github you'll need to set them. For local development, you'll need to set the callback URL to `http://localhost:3000/api/auth/callback/github`

### Payments

To test payments, you can set the following environment variables:

```bash
POLAR_ACCESS_TOKEN=test
POLAR_WEBHOOK_SECRET=test
```

For testing payments, you'll need access to the polar sandbox which needs to be configured to point a webhook to your local server. This can be configured at: <https://sandbox.polar.sh/dashboard/blocknote/settings/webhooks>

You'll need something like [ngrok](https://ngrok.com/) to expose your local server to the internet.

```bash
ngrok http http://localhost:3000
```

You'll need the webhook to point to ngrok like so:

```
https://0000-00-00-000-00.ngrok-free.app/api/auth/polar/webhooks
```

With this webhook pointing to your local server, you should be able to test payments.

### Email sending

Note, this is not required, if email sending is not configured, the app will log the email it would send to the console. Often this is more convenient for development.

To test email sending, you can set the following environment variables:

```bash
SMTP_HOST=
SMTP_USER=
SMTP_PASS=
SMTP_PORT=
SMTP_SECURE=false
```

When configured, you'll be able to send emails to the email address you've configured.

To setup with protonmail, you'll need to go to <https://account.proton.me/u/0/mail/imap-smtp> and create a new SMTP submission token.

You'll need to set the following environment variables:

```bash
SMTP_HOST=smtp.protonmail.com
SMTP_USER=my.email@protonmail.com
SMTP_PASS=my-smtp-token
SMTP_PORT=587
SMTP_SECURE=false
```
4 changes: 4 additions & 0 deletions docs/app/api/auth/[...all]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { auth } from "../../../../auth";
import { toNextJsHandler } from "better-auth/next-js";

export const { POST, GET } = toNextJsHandler(auth);
2 changes: 0 additions & 2 deletions docs/app/api/auth/[...nextauth]/route.ts

This file was deleted.

19 changes: 19 additions & 0 deletions docs/app/portal/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use client";

import { useSession } from "@/util/auth-client";

// Just shows session info
export default function Me() {
const { data: session } = useSession();

if (!session) {
return <div>Not authenticated</div>;
}

return (
<div>
<h1>Welcome {session.user.name}</h1>
<pre>{JSON.stringify(session, null, 2)}</pre>
</div>
);
};
20 changes: 20 additions & 0 deletions docs/app/signin/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Metadata } from "next";
import dynamic from "next/dynamic";
import { Suspense } from "react";

export const metadata: Metadata = {
title: "Login",
};

// dynamic import because we use search params in the client component
const AuthenticationPage = dynamic(
() => import("../../components/AuthenticationPage"),
);

export default function Register() {
return (
<Suspense>
<AuthenticationPage variant="email" />
</Suspense>
);
}
20 changes: 20 additions & 0 deletions docs/app/signin/password/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Metadata } from "next";
import { Suspense } from "react";
import dynamic from "next/dynamic";

export const metadata: Metadata = {
title: "Password Login",
};

// dynamic import because we use search params in the client component
const AuthenticationPage = dynamic(
() => import("../../../components/AuthenticationPage"),
);

export default function Register() {
return (
<Suspense>
<AuthenticationPage variant="password" />
</Suspense>
);
}
20 changes: 20 additions & 0 deletions docs/app/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Metadata } from "next";
import { Suspense } from "react";
import dynamic from "next/dynamic";

// dynamic import because we use search params in the client component
const AuthenticationPage = dynamic(
() => import("../../components/AuthenticationPage"),
);

export const metadata: Metadata = {
title: "Sign-up",
};

export default function Register() {
return (
<Suspense>
<AuthenticationPage variant="register" />
</Suspense>
);
}
Loading
Loading