fix: add auth endpoints to server, fix auth bypass and registration

- server/: commit server code for the first time (was untracked)
  - POST /auth/signup and /auth/login endpoints now deployed
  - GET /v1/billing/summary now verifies user exists in auth_users
    (prevents stale JWTs from bypassing auth → fixes empty dashboard)
- app/_layout.tsx: dual-marker install check (SQLite + SecureStore)
  to detect fresh installs reliably on Android
- app/auth/login.tsx, signup.tsx: replace Ionicons leaf logo with
  actual app icon image (assets/icon.png)
- services/authService.ts: log HTTP status + server message on auth errors

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Timo Knuth
2026-03-02 11:08:32 +01:00
parent 024eec6686
commit 98e5bfbafd
16 changed files with 6025 additions and 0 deletions

86
server/lib/sqlite.js Normal file
View File

@@ -0,0 +1,86 @@
const fs = require('fs');
const path = require('path');
const sqlite3 = require('sqlite3').verbose();
const getDefaultDbPath = () => {
return process.env.PLANT_DB_PATH || path.join(__dirname, '..', 'data', 'greenlns.sqlite');
};
const ensureDbDirectory = (dbPath) => {
const directory = path.dirname(dbPath);
fs.mkdirSync(directory, { recursive: true });
};
const openDatabase = (dbPath = getDefaultDbPath()) => {
ensureDbDirectory(dbPath);
return new Promise((resolve, reject) => {
const db = new sqlite3.Database(dbPath, (error) => {
if (error) {
reject(error);
return;
}
resolve(db);
});
});
};
const closeDatabase = (db) => {
return new Promise((resolve, reject) => {
db.close((error) => {
if (error) {
reject(error);
return;
}
resolve();
});
});
};
const run = (db, sql, params = []) => {
return new Promise((resolve, reject) => {
db.run(sql, params, function onRun(error) {
if (error) {
reject(error);
return;
}
resolve({
lastId: this.lastID,
changes: this.changes,
});
});
});
};
const get = (db, sql, params = []) => {
return new Promise((resolve, reject) => {
db.get(sql, params, (error, row) => {
if (error) {
reject(error);
return;
}
resolve(row || null);
});
});
};
const all = (db, sql, params = []) => {
return new Promise((resolve, reject) => {
db.all(sql, params, (error, rows) => {
if (error) {
reject(error);
return;
}
resolve(rows || []);
});
});
};
module.exports = {
all,
closeDatabase,
get,
getDefaultDbPath,
openDatabase,
run,
};