Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- **Branded HTML magic-link email.** The sign-in email is now a React
Email component (`apps/web/emails/sign-in-magic-link.tsx`) matching
the editorial-technical look of the site — helpbase wordmark, near-
black primary CTA, cool-neutral palette, 10-minute expiry copy, and a
tuned plain-text fallback for clients that don't render HTML. Preview
locally with `pnpm -F web email`.
- **OAuth providers on `/device`.** Opt-in Google + GitHub sign-in
buttons render above the magic-link form when the provider's
`*_CLIENT_ID` and `*_CLIENT_SECRET` env vars are configured on the
Expand Down
2 changes: 1 addition & 1 deletion DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Article body styling lives in `.article-content` at the bottom of `globals.css`.
### Header (`apps/web/components/header.tsx`)

- Sticky top bar with `backdrop-blur-lg` and `bg-background/80`
- Left: small `bg-foreground` rounded square with white "?" mark, "helpbase" wordmark
- Left: "helpbase" wordmark (plain, no icon)
- Center: `<SearchTrigger />` (button that dispatches ⌘K)
- Right: theme toggle, GitHub icon link
- `max-w-6xl` container
Expand Down
7 changes: 2 additions & 5 deletions apps/web/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,8 @@ export function Header() {
<header className="sticky top-0 z-50 w-full border-b border-border/50 bg-background/80 backdrop-blur-lg">
<div className="mx-auto flex h-14 max-w-6xl items-center gap-4 px-6">
{/* Logo */}
<Link href="/" className="flex items-center gap-2 font-semibold tracking-tight">
<div className="flex size-7 items-center justify-center rounded-lg bg-foreground">
<span className="text-xs font-bold text-background">?</span>
</div>
<span className="hidden sm:inline">helpbase</span>
<Link href="/" className="font-semibold tracking-tight">
helpbase
</Link>

{/* Search */}
Expand Down
133 changes: 133 additions & 0 deletions apps/web/emails/sign-in-magic-link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import {
Body,
Button,
Container,
Head,
Hr,
Html,
Link,
Preview,
Section,
Tailwind,
Text,
pixelBasedPreset,
} from "@react-email/components"

interface SignInMagicLinkProps {
url: string
email: string
expiresInMinutes: number
}

export default function SignInMagicLinkEmail({
url,
email,
expiresInMinutes,
}: SignInMagicLinkProps) {
return (
<Html lang="en">
<Tailwind
config={{
presets: [pixelBasedPreset],
theme: {
extend: {
colors: {
// Cool-neutral palette approximations of the in-app shadcn tokens
// (oklch doesn't render in email clients). Matches the
// editorial-technical aesthetic documented in DESIGN.md.
ink: "#0a0a0a",
paper: "#ffffff",
wash: "#fafafa",
border: "#e5e7eb",
muted: "#737373",
},
fontFamily: {
sans: [
"ui-sans-serif",
"system-ui",
"-apple-system",
"BlinkMacSystemFont",
"Segoe UI",
"Roboto",
"Helvetica Neue",
"Arial",
"sans-serif",
],
mono: [
"ui-monospace",
"SFMono-Regular",
"Menlo",
"Monaco",
"Consolas",
"monospace",
],
},
},
},
}}
>
<Head />
<Preview>{`Sign in to helpbase — link expires in ${expiresInMinutes} minutes`}</Preview>
<Body className="bg-wash font-sans py-10">
<Container className="max-w-[520px] mx-auto bg-paper border border-solid border-border rounded-md px-10 py-8">
{/* Wordmark — plain text, matches the site header. */}
<Section>
<Text className="text-ink text-[15px] font-semibold tracking-tight m-0">
helpbase
</Text>
</Section>

<Text className="text-ink text-2xl font-semibold tracking-tight mt-8 mb-2">
Sign in to helpbase
</Text>
<Text className="text-muted text-[15px] leading-6 m-0">
We received a sign-in request for{" "}
<span className="text-ink font-medium">{email}</span>.
Click the button below to continue — the link expires in{" "}
{expiresInMinutes} minutes.
</Text>

<Section className="mt-8 mb-8">
<Button
href={url}
className="bg-ink text-paper no-underline rounded-md box-border px-6 py-3 text-[14px] font-medium"
>
Sign in to helpbase
</Button>
</Section>

<Text className="text-muted text-[13px] leading-5 m-0">
Or copy and paste this URL into your browser:
</Text>
<Text className="font-mono text-[12px] text-ink leading-5 break-all mt-1">
<Link href={url} className="text-ink underline">
{url}
</Link>
</Text>

<Hr className="border-none border-t border-solid border-border my-8" />

<Text className="text-muted text-[12px] leading-5 m-0">
If you didn't request this email, you can safely ignore it —
no action will be taken.
</Text>
<Text className="text-muted text-[12px] leading-5 mt-4 mb-0">
helpbase — docs you can talk to.{" "}
<Link href="https://helpbase.dev" className="text-muted underline">
helpbase.dev
</Link>
</Text>
</Container>
</Body>
</Tailwind>
</Html>
)
}

SignInMagicLinkEmail.PreviewProps = {
url: "https://helpbase.dev/api/auth/magic-link/verify?token=preview_token_1234567890abcdef",
email: "you@example.com",
expiresInMinutes: 10,
} satisfies SignInMagicLinkProps

export { SignInMagicLinkEmail }
25 changes: 22 additions & 3 deletions apps/web/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { magicLink } from "better-auth/plugins/magic-link"
import { deviceAuthorization } from "better-auth/plugins/device-authorization"
import { Pool } from "pg"
import { Resend } from "resend"
import { SignInMagicLinkEmail } from "@/emails/sign-in-magic-link"

const DATABASE_URL = process.env.DATABASE_URL
const RESEND_API_KEY = process.env.RESEND_API_KEY
Expand Down Expand Up @@ -79,15 +80,30 @@ if (!RESEND_API_KEY && isRuntimeProd) {

const resend = RESEND_API_KEY ? new Resend(RESEND_API_KEY) : null

// Keep in sync with the magicLink plugin's `expiresIn` below. Used both by
// the email template copy and the text fallback so they never drift.
const MAGIC_LINK_EXPIRES_MINUTES = 10

async function deliverMagicLink(email: string, url: string): Promise<void> {
if (resend) {
const { error } = await resend.emails.send({
from: FROM_EMAIL,
to: email,
subject: "Sign in to helpbase",
// Resend renders the React component to HTML server-side. The `text`
// fallback is kept explicit (rather than letting Resend auto-generate
// one from the component) so plain-text-only clients get copy tuned
// for that surface — no stripped-down HTML leftovers.
react: SignInMagicLinkEmail({
url,
email,
expiresInMinutes: MAGIC_LINK_EXPIRES_MINUTES,
}),
text:
`Click the link below to sign in:\n\n${url}\n\n` +
`This link expires in 10 minutes. If you didn't request this, ignore this email.`,
`Sign in to helpbase\n\n` +
`Click the link below to continue:\n${url}\n\n` +
`This link expires in ${MAGIC_LINK_EXPIRES_MINUTES} minutes.\n` +
`If you didn't request this email, you can ignore it.`,
})
if (error) {
// Let Better Auth surface the error to the caller. The CLI's
Expand Down Expand Up @@ -125,7 +141,10 @@ export const auth = betterAuth({
plugins: [
bearer(),
magicLink({
expiresIn: 600, // 10 minutes; Better Auth default is 300 which is tight for mobile mail delivery
// Keep in sync with MAGIC_LINK_EXPIRES_MINUTES above (the email copy
// references it). Better Auth's default 300s is tight for mobile mail
// delivery; 10m gives most carriers a comfortable window.
expiresIn: MAGIC_LINK_EXPIRES_MINUTES * 60,
sendMagicLink: async ({ email, url }) => {
await deliverMagicLink(email, url)
},
Expand Down
6 changes: 5 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"lint": "eslint",
"format": "prettier --write \"**/*.{ts,tsx}\"",
"typecheck": "tsc --noEmit",
"test": "vitest run"
"test": "vitest run",
"email": "email dev --dir emails --port 3001"
},
"dependencies": {
"@helpbase/mcp": "workspace:*",
"@modelcontextprotocol/sdk": "^1.29.0",
"@react-email/components": "^1.0.12",
"@supabase/supabase-js": "^2.103.0",
"@vercel/kv": "^3.0.0",
"@workspace/shared": "workspace:*",
Expand All @@ -40,6 +42,7 @@
"zod": "^4.3.6"
},
"devDependencies": {
"@react-email/ui": "6.0.0",
"@tailwindcss/postcss": "^4.1.18",
"@tailwindcss/typography": "^0.5.19",
"@types/node": "^25.1.0",
Expand All @@ -49,6 +52,7 @@
"@workspace/eslint-config": "workspace:^",
"@workspace/typescript-config": "workspace:*",
"eslint": "^9.39.2",
"react-email": "^6.0.0",
"tailwindcss": "^4.1.18",
"typescript": "^5.9.3"
}
Expand Down
Loading
Loading