Skip to content

Commit 2c5e907

Browse files
fix: initialize profiles before dashboard reads and verify free Gemini model
1 parent c181c4f commit 2c5e907

10 files changed

Lines changed: 30 additions & 24 deletions

File tree

‎.env.example‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ARCJET_KEY=
1717
# Optional integrations; required only for their respective features
1818
GEMINI_API_KEY=
1919
# Both receipt scanning and reports use this model. Verify access with your key.
20-
GEMINI_MODEL=gemini-3.8-flash
20+
GEMINI_MODEL=gemini-3.5-flash-lite
2121
RESEND_API_KEY=
2222
# This spelling intentionally matches app/api/exchangeRates/route.js.
2323
OPEN_EXCANGE_API_KEY=

‎README.de.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Next.js 15 und React 19 bilden die Anwendung. Die Oberfläche nutzt Tailwind CSS
5555

5656
## Stand und Grenzen
5757

58-
Das Projekt ist eine Demo. Belegscan und Monatsberichte verwenden jetzt gemeinsam `GEMINI_MODEL`, standardmäßig `gemini-3.8-flash`. Für den Gratis-Start wird ein Google-AI-Studio-Projekt im Free-Tarif ohne aktivierte kostenpflichtige Abrechnung verwendet. Die tatsächlichen Kontingente sind projektabhängig. Der Belegscan benötigt eine Anmeldung und begrenzt Versuche auf fünf pro Nutzer mit Auffüllung nach 24 Stunden. Ein echter API-Test mit eigenem Schlüssel steht aus. Siehe [KI kostenlos einrichten](docs/AI.md).
58+
Das Projekt ist eine Demo. Belegscan und Monatsberichte verwenden jetzt gemeinsam `GEMINI_MODEL`, standardmäßig `gemini-3.5-flash-lite`. Der Free-Tarif des Demo-Projekts ohne aktivierte Abrechnung wurde in AI Studio bestätigt. Ein echter API-Test mit erfundenem Belegtext lieferte die erwarteten JSON-Daten. Die tatsächlichen Kontingente sind projektabhängig. Der Belegscan benötigt eine Anmeldung und begrenzt Versuche auf fünf pro Nutzer mit Auffüllung nach 24 Stunden. Der Bildscan über die angemeldete Oberfläche und der Berichtversand müssen separat geprüft werden. Siehe [KI kostenlos einrichten](docs/AI.md).
5959

6060
Der alte Seed-Endpunkt ist deaktiviert und antwortet mit HTTP 410. Das bisherige Skript mit festen IDs wird darüber nicht mehr ausgeführt. Next.js und seine Prüfkonfiguration wurden auf die abgesicherte Version 15.5.28 aktualisiert; geschützte Routen und die Anmeldeweiterleitung sind korrigiert.
6161

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ The [quality workflow](.github/workflows/quality.yml) checks lint, unit tests, t
151151

152152
This repository is a **demo**, with implemented product flows and some unfinished integration details:
153153

154-
- **AI configuration:** the retired Gemini 1.5 model has been replaced by a shared [`GEMINI_MODEL` configuration](lib/gemini.mjs), defaulting to `gemini-3.8-flash`. Google currently lists a [Free tier](https://ai.google.dev/gemini-api/docs/pricing) for this model. Use a Free-tier project without paid billing, check its actual quotas in AI Studio and verify model access with your own key. This change has not been live-tested against Google. See [free AI setup](docs/AI.md).
154+
- **AI configuration:** the retired Gemini 1.5 model has been replaced by a shared [`GEMINI_MODEL` configuration](lib/gemini.mjs), defaulting to `gemini-3.5-flash-lite`. Google currently lists a [Free tier](https://ai.google.dev/gemini-api/docs/pricing) for this model. The demo project's Free tier was confirmed in AI Studio, and a live fictional receipt-text test returned the expected JSON. Your own project's access and quotas still require verification. See [free AI setup](docs/AI.md).
155155
- **Seed endpoint:** the legacy `/api/seed` route is disabled and returns HTTP 410. It does not execute the old generator with fixed user/account IDs. Add fictional transactions through the account interface instead.
156156
- **Landing-page content:** usage numbers, ratings and testimonials are demonstration copy, not verified customer or operational metrics. Existing illustrations are not application screenshots.
157157
- **Deployment readiness:** Next.js and its ESLint configuration are updated to 15.5.28, the currently documented patched 15.x release. Protected-route matching and the sign-in redirect have been corrected. Receipt scans require authentication, reject unsupported or oversized files server-side and use a dedicated Arcjet limit. Provider configuration, recurring-job behavior and end-to-end use still need verification before real financial data is used.

‎actions/dashboard.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import {auth} from "@clerk/nextjs/server";
44
import {db} from "@/lib/prisma";
55
import {revalidatePath} from "next/cache";
6+
import {checkUser} from "@/lib/checkUser";
67

78
const serializeTransaction = (obj) => {
89
const serialized = {...obj};
@@ -93,11 +94,8 @@ export async function getUserAccounts() {
9394
throw new Error("Unauthorized");
9495
}
9596

96-
const user = await db.user.findUnique({
97-
where: {
98-
clerkUserId: userId,
99-
},
100-
});
97+
// Ensure onboarding finishes before querying accounts in a fresh database.
98+
const user = await checkUser();
10199

102100
if(!user) {
103101
throw new Error("User not found");
@@ -147,4 +145,4 @@ export async function getDashboardData() {
147145
});
148146

149147
return transactions.map(serializeTransaction);
150-
}
148+
}

‎docs/AI.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Recommended starting point
66

7-
Use the **Gemini Developer API Free tier** for the first demo. The application already uses Google's SDK, and Google currently lists free input/output tokens for `gemini-3.8-flash`. Actual eligibility, model access and capacity belong to your Google project; they cannot be guaranteed by this repository.
7+
Use the **Gemini Developer API Free tier** for the first demo. The application already uses Google's SDK, and Google currently lists free input/output tokens for `gemini-3.5-flash-lite`. Actual eligibility, model access and capacity belong to your Google project; they cannot be guaranteed by this repository.
88

99
OpenAI could power the same text and image workflows through a different adapter, but its normal generative API pricing does not provide a generally guaranteed free allowance for these tasks. A ChatGPT subscription is not a substitute for API billing. This repository therefore keeps Gemini as its only AI provider for the free-first setup and does not add a paid fallback.
1010

@@ -15,7 +15,7 @@ Official sources, checked October 25, 2026: [Google pricing](https://ai.google.d
1515
1. Open **[Google AI Studio API keys](https://aistudio.google.com/apikey)** and sign in.
1616
2. Create or choose a project in the **Free** tier. Do not enable paid billing for a zero-cost demo. A key belonging to an already billed project can produce charges; the app cannot infer the project's billing tier from the key.
1717
3. Create a key restricted to the Gemini API, following [Google's key guide](https://ai.google.dev/gemini-api/docs/api-key).
18-
4. In the local, Git-ignored `.env` file, set `GEMINI_API_KEY` to your key and leave `GEMINI_MODEL=gemini-3.8-flash` unless your project's model availability requires a change.
18+
4. In the local, Git-ignored `.env` file, set `GEMINI_API_KEY` to your key and leave `GEMINI_MODEL=gemini-3.5-flash-lite` unless your project's model availability requires a change.
1919
5. Restart the full application. Keep the key on the server; do not post it in issues, screenshots, chat transcripts or Git commits.
2020
6. Open the project's rate-limit view in AI Studio. The minute, token and daily limits shown there are authoritative for that project.
2121

@@ -36,7 +36,7 @@ The per-user scan bucket is not a global project cost cap. Monthly reports also
3636

3737
## Verification and data handling
3838

39-
Unit tests cover missing keys, shared model selection, retired-model rejection and receipt upload boundaries. They do not contact Google. A live model-list request with an owner-supplied key confirmed authentication and availability of `gemini-3.8-flash`; it generated no content and does not establish free quota or billing status. A live receipt scan and report generation remain unverified until a configured integration run succeeds.
39+
Unit tests cover missing keys, shared model selection, retired-model rejection and receipt upload boundaries. They do not contact Google. On October 25, 2026, AI Studio showed the demo project's Free tier with billing not enabled. A live SDK request using fictional receipt text and `gemini-3.5-flash-lite` returned valid JSON with the expected amount and date. The initially selected `gemini-3.8-flash` returned 503 overload errors twice, so the demo now selects Flash-Lite explicitly. This is not an automatic fallback. Image upload through the authenticated UI and scheduled report delivery still need separate integration checks.
4040

4141
Use fictional receipt data initially. Receipt images and monthly aggregate statistics leave the application when those features call Google. Review the provider terms applicable to your location and tier before using personal financial data; the [pricing page](https://ai.google.dev/gemini-api/docs/pricing) links to the relevant data-use terms.
4242

‎docs/SETUP.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Copy-Item .env.example .env
4848
| `NEXT_PUBLIC_CLERK_SIGN_UP_FALLBACK_REDIRECT_URL` | Default destination after sign-up; `/dashboard`. | Configuring sign-up navigation. |
4949
| `ARCJET_KEY` | Shield, bot detection and transaction rate limiting. | Starting the main application. |
5050
| `GEMINI_API_KEY` | Receipt extraction and monthly AI insights. | Enabling AI features. |
51-
| `GEMINI_MODEL` | Shared model selection; defaults to `gemini-3.8-flash`. | Optional override; verify availability in your project. |
51+
| `GEMINI_MODEL` | Shared model selection; defaults to `gemini-3.5-flash-lite`. | Optional override; verify availability in your project. |
5252
| `RESEND_API_KEY` | Budget-alert and monthly-report delivery. | Sending email. |
5353
| `OPEN_EXCANGE_API_KEY` | `/api/exchangeRates`. The spelling matches the existing code. | Using exchange-rate data. |
5454
| `INNGEST_EVENT_KEY` | Send events to Inngest Cloud. | Deploying background jobs to Inngest Cloud. |
@@ -82,7 +82,7 @@ Open [localhost:3000](http://localhost:3000), sign up and create your first acco
8282

8383
### Receipt scanning and AI reports
8484

85-
Provide `GEMINI_API_KEY` and optionally `GEMINI_MODEL`. Both integrations now use [`lib/gemini.mjs`](../lib/gemini.mjs), which defaults to `gemini-3.8-flash`, requests JSON output and caps output at 2,048 tokens. It rejects retired Gemini 1.5 model IDs. Check provider access and actual output with your project's key before considering AI verified. See [AI.md](AI.md) for the Free-tier setup and limits.
85+
Provide `GEMINI_API_KEY` and optionally `GEMINI_MODEL`. Both integrations now use [`lib/gemini.mjs`](../lib/gemini.mjs), which defaults to `gemini-3.5-flash-lite`, requests JSON output and caps output at 2,048 tokens. It rejects retired Gemini 1.5 model IDs. Check provider access and actual output with your project's key before considering AI verified. See [AI.md](AI.md) for the Free-tier setup and limits.
8686

8787
The receipt uploader and Server Action both check for non-empty JPEG, PNG or WebP files of at most 4 MiB, leaving room beneath the 5 MB Server Action body limit. Scanning requires authentication and a separate Arcjet bucket of five attempts per user, refilling every 24 hours. Provider project quotas apply in addition. Confirm every extracted field before saving.
8888

‎lib/checkUser.js‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {currentUser} from "@clerk/nextjs/server";
22
import {db} from "@/lib/prisma";
3-
import {error} from "next/dist/build/output/log";
3+
import {cache} from "react";
44

55

6-
export const checkUser = async() => {
6+
export const checkUser = cache(async() => {
77
const user =await currentUser();
88

99
if(!user) {
@@ -22,20 +22,25 @@ export const checkUser = async() => {
2222
}
2323

2424

25-
const name = `${user.firstName} ${user.lastName}`;
25+
const name = [user.firstName, user.lastName].filter(Boolean).join(" ") || user.username || "Prudentis user";
26+
const email = user.primaryEmailAddress?.emailAddress || user.emailAddresses[0]?.emailAddress;
27+
if (!email) throw new Error("An email address is required to create your profile.");
2628

27-
const newUser = await db.user.create({
28-
data: {
29+
// Layouts and pages may render concurrently on the first signed-in request.
30+
const newUser = await db.user.upsert({
31+
where: {clerkUserId: user.id},
32+
update: {},
33+
create: {
2934
clerkUserId: user.id,
3035
name,
3136
imageUrl: user.imageUrl,
32-
email: user.emailAddresses[0].emailAddress,
37+
email,
3338
},
3439
});
3540

3641
return newUser;
3742
}catch (error) {
3843
console.log(error.message);
39-
return null;
44+
throw new Error("Could not initialize your Prudentis profile.");
4045
}
41-
};
46+
});

‎lib/gemini.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function getGeminiModel() {
88
throw new Error("GEMINI_API_KEY is required to use AI features.");
99
}
1010

11-
const model = process.env.GEMINI_MODEL?.trim() || "gemini-3.8-flash";
11+
const model = process.env.GEMINI_MODEL?.trim() || "gemini-3.5-flash-lite";
1212
if (/^(?:models\/)?gemini-1\.5(?:-|$)/.test(model)) {
1313
throw new Error("Gemini 1.5 has been shut down. Set GEMINI_MODEL to an available model.");
1414
}

‎next.config.mjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
async redirects() {
4+
return [{source: "/favicon.png", destination: "/favicon.ico", permanent: true}];
5+
},
36
images: {
47
remotePatterns: [
58
{

‎tests/gemini.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test("shared Gemini configuration", async (t) => {
2020
process.env.GEMINI_API_KEY = "test-only-placeholder";
2121
await t.test("unset model selects the documented default", () => {
2222
delete process.env.GEMINI_MODEL;
23-
assert.equal(getGeminiModel().model, "models/gemini-3.8-flash");
23+
assert.equal(getGeminiModel().model, "models/gemini-3.5-flash-lite");
2424
});
2525

2626
await t.test("configured models are shared and whitespace is trimmed", () => {

0 commit comments

Comments
 (0)