Files
dashback/src/db/googleAuth.js
seb fc2b136c46 Store Google avatar bytes and slim the session JWT to id only.
Download profile images on login into picturebinary, return them as base64 from /auth/me, and resolve sessions via getById.
2026-08-05 11:12:36 +02:00

44 lines
1.4 KiB
JavaScript

import { getStore } from './store.js';
export async function listAllowedEmails() {
const store = await getStore();
return store.google_auth.listAllowedEmails();
}
export async function getAllowedEmail(email) {
const normalized = email.trim().toLowerCase();
const store = await getStore();
return (await store.google_auth.getByEmail(normalized)) ?? null;
}
export async function getById(authId) {
const store = await getStore();
return (await store.google_auth.getById(authId)) ?? null;
}
export async function addAllowedEmail(email) {
const normalized = email.trim().toLowerCase();
const store = await getStore();
const id = await store.google_auth.add(normalized);
return { id, email: normalized };
}
export async function removeAllowedEmail(email) {
const normalized = email.trim().toLowerCase();
const row = await getAllowedEmail(normalized);
if (!row) return false;
const store = await getStore();
await store.google_auth.removeAllowedEmail(normalized);
return true;
}
export async function setSelectedCompany(authId, companyId) {
const store = await getStore();
await store.google_auth.setSelectedCompany(authId, companyId);
}
export async function setProfile(authId, { picture = null, pictureBinary = null, sub = null } = {}) {
const store = await getStore();
await store.google_auth.setProfile(authId, { picture, pictureBinary, sub });
}