Store Google profile picture bytes on google_auth

This commit is contained in:
seb
2026-08-05 11:08:06 +02:00
parent d1eb2716ae
commit 561ba5bb99
9 changed files with 859 additions and 812 deletions

View File

@@ -58,6 +58,7 @@ import taxEnsure from './store/tax/ensure.js';
import taxList from './store/tax/list.js';
import googleAuthAdd from './store/google_auth/add.js';
import googleAuthGetByEmail from './store/google_auth/getByEmail.js';
import googleAuthGetById from './store/google_auth/getById.js';
import googleAuthListAllowedEmails from './store/google_auth/listAllowedEmails.js';
import googleAuthRemoveAllowedEmail from './store/google_auth/removeAllowedEmail.js';
import googleAuthSetSelectedCompany from './store/google_auth/setSelectedCompany.js';
@@ -162,6 +163,7 @@ export default class LibDashStore {
this.google_auth = {
add: googleAuthAdd(pool),
getByEmail: googleAuthGetByEmail(pool),
getById: googleAuthGetById(pool),
listAllowedEmails: googleAuthListAllowedEmails(pool),
removeAllowedEmail: googleAuthRemoveAllowedEmail(pool),
setSelectedCompany: googleAuthSetSelectedCompany(pool),

View File

@@ -22,6 +22,7 @@ BEGIN
id INT IDENTITY(1,1) PRIMARY KEY,
email NVARCHAR(320) NOT NULL,
picture NVARCHAR(2048) NULL,
picturebinary VARBINARY(MAX) NULL,
sub NVARCHAR(255) NULL,
created_at DATETIME2 NOT NULL CONSTRAINT DF_google_auth_created_at DEFAULT SYSUTCDATETIME(),
selected_company INT NULL,

View File

@@ -4,18 +4,30 @@ OUTPUT INSERTED.id
VALUES (@email)
`;
export const GET_BY_EMAIL = `
SELECT
export const GOOGLE_AUTH_COLUMNS = `
id,
email,
picture,
picturebinary AS pictureBinary,
sub,
created_at AS createdAt,
selected_company AS selectedCompanyId
`;
export const GET_BY_EMAIL = `
SELECT
${GOOGLE_AUTH_COLUMNS}
FROM google_auth
WHERE email = @email
`;
export const GET_BY_ID = `
SELECT
${GOOGLE_AUTH_COLUMNS}
FROM google_auth
WHERE id = @googleAuthId
`;
export const LIST_ALLOWED_EMAILS = `
SELECT
id,
@@ -41,6 +53,6 @@ WHERE id = @googleAuthId
export const SET_PROFILE = `
UPDATE google_auth
SET picture = @picture, sub = @sub
SET picture = @picture, picturebinary = @pictureBinary, sub = @sub
WHERE id = @googleAuthId
`;

View File

@@ -0,0 +1,12 @@
import { GET_BY_ID } from '../../sql/google_auth.js';
export default function getById(pool) {
return async (googleAuthId) => {
const result = await pool
.request()
.input('googleAuthId', googleAuthId)
.query(GET_BY_ID);
return result.recordset[0];
};
}

View File

@@ -1,11 +1,19 @@
import { SET_PROFILE } from '../../sql/google_auth.js';
export default function setProfile(pool) {
return async (googleAuthId, { picture = null, sub = null } = {}) => {
return async (
googleAuthId,
{ picture = null, pictureBinary = null, sub = null } = {},
) => {
if (pictureBinary != null && !Buffer.isBuffer(pictureBinary)) {
throw new Error('Invalid pictureBinary');
}
const result = await pool
.request()
.input('googleAuthId', googleAuthId)
.input('picture', picture)
.input('pictureBinary', pictureBinary)
.input('sub', sub)
.query(SET_PROFILE);