xiaohongshu
xiaohongshu
heartwood-auth
Integrate Heartwood (GroveAuth) authentication into Grove applications. Use when adding sign-in, protecting routes, or validating sessions in any Grove property.
Full skill instructions
Activate this skill when:
Heartwood is Grove's centralized authentication service powered by Better Auth.
| Domain | Purpose |
|---|---|
heartwood.grove.place | Frontend (login UI) |
auth-api.grove.place | Backend API |
For new integrations, use Better Auth's client library:
// src/lib/auth/client.ts
import { createAuthClient } from 'better-auth/client';
export const auth = createAuthClient({
baseURL: 'https://auth-api.grove.place'
});
// Sign in with Google
await auth.signIn.social({ provider: 'google' });
// Get current session
const session = await auth.getSession();
// Sign out
await auth.signOut();
For apps on .grove.place subdomains, sessions work automatically via cookies:
// src/hooks.server.ts
import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {
// Check session via Heartwood API
const sessionCookie = event.cookies.get('better-auth.session_token');
if (sessionCookie) {
try {
const response = await fetch('https://auth-api.grove.place/api/auth/session', {
headers: {
Cookie: `better-auth.session_token=${sessionCookie}`
}
});
if (response.ok) {
const data = await response.json();
event.locals.user = data.user;
event.locals.session = data.session;
}
} catch {
// Session invalid or expired
}
}
return resolve(event);
};
For existing integrations using the legacy OAuth flow:
// 1. Redirect to Heartwood login
const params = new URLSearchParams({
client_id: 'your-client-id',
redirect_uri: 'https://yourapp.grove.place/auth/callback',
state: crypto.randomUUID(),
code_challenge: await generateCodeChallenge(verifier),
code_challenge_method: 'S256'
});
redirect(302, `https://auth-api.grove.place/login?${params}`);
// 2. Exchange code for tokens (in callback route)
const tokens = await fetch('https://auth-api.grove.place/token', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
grant_type: 'authorization_code',
code: code,
redirect_uri: 'https://yourapp.grove.place/auth/callback',
client_id: 'your-client-id',
client_secret: env.HEARTWOOD_CLIENT_SECRET,
code_verifier: verifier
})
}).then(r => r.json());
// 3. Verify token on protected routes
const user = await fetch('https://auth-api.grove.place/verify', {
headers: { Authorization: `Bearer ${tokens.access_token}` }
}).then(r => r.json());
// src/routes/admin/+layout.server.ts
import { redirect } from '@sveltejs/kit';
import type { LayoutServerLoad } from './$types';
export const load: LayoutServerLoad = async ({ locals }) => {
if (!locals.user) {
throw redirect(302, '/auth/login');
}
return {
user: locals.user
};
};
// src/routes/api/protected/+server.ts
import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ locals }) => {
if (!locals.user) {
throw error(401, 'Unauthorized');
}
return json({ message: 'Protected data', user: locals.user });
};
async function validateSession(sessionToken: string) {
const response = await fetch('https://auth-api.grove.place/api/auth/session', {
headers: {
Cookie: `better-auth.session_token=${sessionToken}`
}
});
if (!response.ok) return null;
const data = await response.json();
return data.session ? data : null;
}
async function validateToken(accessToken: string) {
const response = await fetch('https://auth-api.grove.place/verify', {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
const data = await response.json();
return data.active ? data : null;
}
To integrate a new app with Heartwood, you need to register it as a client.
# Generate a secure client secret
openssl rand -base64 32
# Example: YKzJChC3RPjZvd1f/OD5zUGAvcouOTXG7maQP1ernCg=
# Hash it for storage (base64url encoding)
echo -n "YOUR_SECRET" | openssl dgst -sha256 -binary | base64 | tr '+/' '-_' | tr -d '='
INSERT INTO clients (id, name, client_id, client_secret_hash, redirect_uris, allowed_origins)
VALUES (
lower(hex(randomblob(16))),
'Your App Name',
'your-app-id',
'BASE64URL_HASHED_SECRET',
'["https://yourapp.grove.place/auth/callback"]',
'["https://yourapp.grove.place"]'
);
# Set the client secret on your app
wrangler secret put HEARTWOOD_CLIENT_SECRET
# Paste: YKzJChC3RPjZvd1f/OD5zUGAvcouOTXG7maQP1ernCg=
| Variable | Description |
|---|---|
HEARTWOOD_CLIENT_ID | Your registered client ID |
HEARTWOOD_CLIENT_SECRET | Your client secret (never commit!) |
| Method | Endpoint | Purpose |
|---|---|---|
| POST | /api/auth/sign-in/social | OAuth sign-in |
| POST | /api/auth/sign-in/magic-link | Magic link sign-in |
| POST | /api/auth/sign-in/passkey | Passkey sign-in |
| GET | /api/auth/session | Get current session |
| POST | /api/auth/sign-out | Sign out |
| Method | Endpoint | Purpose |
|---|---|---|
| GET | /login | Login page |
| POST | /token | Exchange code for tokens |
| GET | /verify | Validate access token |
| GET | /userinfo | Get user info |
httpOnly cookies for token storageAll .grove.place apps share the same session cookie automatically:
better-auth.session_token (domain=.grove.place)
Once a user signs in on any Grove property, they're signed in everywhere.
.grove.place/Users/autumn/Documents/Projects/GroveAuth/GROVEAUTH_SPEC.md/Users/autumn/Documents/Projects/GroveAuth/docs/OAUTH_CLIENT_SETUP.mdxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience