feat: move API keys storage to Postgres database instead of localStorage
Build and Deploy / build-and-push (push) Failing after 21s
Build and Deploy / build-and-push (push) Failing after 21s
This commit is contained in:
@@ -116,6 +116,40 @@ app.get('/api/auth/me', authenticate, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 3.5. Get User API Keys
|
||||
app.get('/api/user/keys', authenticate, async (req, res) => {
|
||||
try {
|
||||
const profile = await get('SELECT api_keys FROM profiles WHERE id = ?', [req.user.id]);
|
||||
let keys = {};
|
||||
if (profile && profile.api_keys) {
|
||||
try {
|
||||
keys = JSON.parse(profile.api_keys);
|
||||
} catch (e) {
|
||||
// ignore invalid json
|
||||
}
|
||||
}
|
||||
res.json({ keys });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// 3.6. Update User API Keys
|
||||
app.put('/api/user/keys', authenticate, async (req, res) => {
|
||||
const { keys } = req.body;
|
||||
if (!keys || typeof keys !== 'object') {
|
||||
return res.status(400).json({ error: 'Invalid keys object' });
|
||||
}
|
||||
|
||||
try {
|
||||
const keysStr = JSON.stringify(keys);
|
||||
await run('UPDATE profiles SET api_keys = ? WHERE id = ?', [keysStr, req.user.id]);
|
||||
res.json({ success: true });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// 4. Get all projects for user
|
||||
app.get('/api/projects', authenticate, async (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user