u
This commit is contained in:
@@ -1,34 +1,27 @@
|
||||
import { getDb } from './client.js';
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export function listAllowedEmails() {
|
||||
return getDb()
|
||||
.prepare('SELECT id, email, created_at FROM google_auth ORDER BY email COLLATE NOCASE')
|
||||
.all();
|
||||
export async function listAllowedEmails() {
|
||||
const store = await getStore();
|
||||
return store.google_auth.list();
|
||||
}
|
||||
|
||||
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) {
|
||||
export async function getAllowedEmail(email) {
|
||||
const normalized = email.trim().toLowerCase();
|
||||
const result = getDb()
|
||||
.prepare('INSERT INTO google_auth (email) VALUES (?)')
|
||||
.run(normalized);
|
||||
return getAllowedEmailById(result.lastInsertRowid);
|
||||
const store = await getStore();
|
||||
return (await store.google_auth.getByEmail(normalized)) ?? null;
|
||||
}
|
||||
|
||||
export function removeAllowedEmail(email) {
|
||||
export async function addAllowedEmail(email) {
|
||||
const normalized = email.trim().toLowerCase();
|
||||
return getDb()
|
||||
.prepare('DELETE FROM google_auth WHERE email = ? COLLATE NOCASE')
|
||||
.run(normalized).changes > 0;
|
||||
const store = await getStore();
|
||||
const id = await store.google_auth.add(normalized);
|
||||
return { id, email: normalized };
|
||||
}
|
||||
|
||||
export async function removeAllowedEmail(email) {
|
||||
const row = await getAllowedEmail(email);
|
||||
if (!row) return false;
|
||||
const store = await getStore();
|
||||
await store.google_auth.del(row.id);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user