Admin sync fixes

This commit is contained in:
Ben Allfree 2024-01-13 05:56:52 -08:00
parent 98df4a2586
commit a8080c3d11
2 changed files with 14 additions and 4 deletions

View File

@ -1,10 +1,12 @@
onAfterBootstrap((e) => {
$app.onBeforeServe().add((e) => {
const dao = $app.dao()
const { mkLog } = /** @type {Lib} */ (require(`${__hooks}/_ph_lib.js`))
const log = mkLog(`admin-sync`)
const { email, tokenKey, passwordHash } = JSON.parse($os.getenv(`ADMIN_SYNC`))
const { id, email, tokenKey, passwordHash } = JSON.parse(
$os.getenv(`ADMIN_SYNC`),
)
if (!email) {
log(`Not active - skipped`)
@ -43,9 +45,16 @@ onAfterBootstrap((e) => {
dao
.db()
.newQuery(
'insert into _admins (email, tokenKey, passwordHash) VALUES ({:email}, {:tokenKey}, {:passwordHash})',
'insert into _admins (id,email, tokenKey, passwordHash) VALUES ({:id}, {:email}, {:tokenKey}, {:passwordHash})',
)
.bind({ email, tokenKey, passwordHash })
.bind({
id,
email,
tokenKey,
passwordHash,
created: new Date().toISOString(),
updated: new Date().toISOString(),
})
.execute()
log(`Success`)
} catch (e) {

View File

@ -284,6 +284,7 @@ export const instanceService = mkSingleton(
await client.getUserTokenInfo({ id })
dbg(`Token info is`, { email, tokenKey, passwordHash })
spawnArgs.env!.ADMIN_SYNC = stringify({
id,
email,
tokenKey,
passwordHash,