Genesis
This commit is contained in:
34
src/db/googleAuth.js
Normal file
34
src/db/googleAuth.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { getDb } from './client.js';
|
||||
|
||||
export function listAllowedEmails() {
|
||||
return getDb()
|
||||
.prepare('SELECT id, email, created_at FROM google_auth ORDER BY email COLLATE NOCASE')
|
||||
.all();
|
||||
}
|
||||
|
||||
export function getAllowedEmail(email) {
|
||||
return getDb()
|
||||
.prepare('SELECT id, email, created_at FROM google_auth WHERE email = ? COLLATE NOCASE')
|
||||
.get(email);
|
||||
}
|
||||
|
||||
export function getAllowedEmailById(id) {
|
||||
return getDb()
|
||||
.prepare('SELECT id, email, created_at FROM google_auth WHERE id = ?')
|
||||
.get(id);
|
||||
}
|
||||
|
||||
export function addAllowedEmail(email) {
|
||||
const normalized = email.trim().toLowerCase();
|
||||
const result = getDb()
|
||||
.prepare('INSERT INTO google_auth (email) VALUES (?)')
|
||||
.run(normalized);
|
||||
return getAllowedEmailById(result.lastInsertRowid);
|
||||
}
|
||||
|
||||
export function removeAllowedEmail(email) {
|
||||
const normalized = email.trim().toLowerCase();
|
||||
return getDb()
|
||||
.prepare('DELETE FROM google_auth WHERE email = ? COLLATE NOCASE')
|
||||
.run(normalized).changes > 0;
|
||||
}
|
||||
Reference in New Issue
Block a user