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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ CRON_SECRET=replace-with-a-long-random-string
APP_URL=http://localhost:3000
# Generate a different value per deployment with: openssl rand -base64 32
BETTER_AUTH_SECRET=
# Optional server-side key for Dash ownership verification at /api/auth.
BETTER_AUTH_API_KEY=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ Buka [localhost:3000](http://localhost:3000). Aplikasi berjalan dengan penyimpan
| `CRON_SECRET` | Mengamankan cron transaksi berulang (harian, 08.00 WIB) |
| `APP_URL` | URL publik kanonis untuk Better Auth dan Google OAuth (wajib untuk mode akun, HTTPS di Vercel) |
| `BETTER_AUTH_SECRET` | Kunci privat Better Auth, minimal 32 karakter (wajib untuk mode akun). Buat dengan `openssl rand -base64 32`. |
| `BETTER_AUTH_API_KEY` | Kunci server opsional untuk verifikasi kepemilikan Better Auth Dash. Tambahkan ke environment Production di Vercel, deploy ulang, lalu verifikasi menggunakan `APP_URL/api/auth`. |
| `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` | Login Google (opsional) |
| `GOLDPRICE_API_KEY` | Secret server untuk mengambil harga spot emas dari Goldprice (opsional; dibutuhkan untuk harga live) |

Expand Down
58 changes: 58 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"license": "MIT",
"type": "commonjs",
"dependencies": {
"@better-auth/infra": "0.4.34",
"bcryptjs": "^3.0.3",
"better-auth": "1.7.29",
"jszip": "^3.10.2",
Expand Down
35 changes: 35 additions & 0 deletions src/app/api/auth/dash/validate/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { dash } from '@better-auth/infra';
import { betterAuth } from 'better-auth';
import { appOrigin } from '@/server/auth-providers';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

// Keep Dash verification separate from account routes and their database.
function createDashAuth(baseURL: string, secret: string, apiKey: string) {
return betterAuth({
baseURL,
basePath: '/api/auth',
secret,
telemetry: { enabled: false },
plugins: [dash({ apiKey })],
});
}

let auth: ReturnType<typeof createDashAuth> | undefined;

export async function GET(request: Request) {
const apiKey = process.env.BETTER_AUTH_API_KEY?.trim();
const secret = process.env.BETTER_AUTH_SECRET;
const baseURL = appOrigin(process.env.APP_URL);

if (!apiKey || !baseURL || !secret || secret.length < 32) {
return new Response(null, { status: 404, headers: { 'Cache-Control': 'no-store' } });
}

auth ??= createDashAuth(baseURL, secret, apiKey);
const response = await auth.handler(request);
const headers = new Headers(response.headers);
headers.set('Cache-Control', 'no-store');
return new Response(response.body, { status: response.status, headers });
}
Loading