Store Google profile picture bytes on google_auth
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
`;
|
||||
|
||||
12
src/store/google_auth/getById.js
Normal file
12
src/store/google_auth/getById.js
Normal 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];
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user