mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
Create first admin user
This commit is contained in:
parent
28029af0b1
commit
64b21bd2db
@ -3,8 +3,8 @@ PUBLIC_APP_DOMAIN=pockethost.test
|
||||
PUBLIC_APP_DB=pockethost-central
|
||||
DAEMON_PB_BIN_DIR=`pwd`/packages/pocketbase/dist
|
||||
DAEMON_PB_DATA_DIR=`pwd`/.data
|
||||
DAEMON_PB_USERNAME=#ADDME
|
||||
DAEMON_PB_PASSWORD=#FIXME
|
||||
DAEMON_PB_USERNAME=admin@pockethost.test
|
||||
DAEMON_PB_PASSWORD=password
|
||||
DAEMON_PB_PORT=8090
|
||||
DAEMON_IDLE_TTL=5000
|
||||
DAEMON_PB_BACKUP_SLEEP=100
|
||||
|
@ -32,6 +32,7 @@ export const withInstance = safeCatch(
|
||||
`***WARNING*** CANNOT AUTHENTICATE TO ${PUBLIC_APP_PROTOCOL}://${PUBLIC_APP_DB}.${PUBLIC_APP_DOMAIN}/_/`
|
||||
)
|
||||
error(`***WARNING*** LOG IN MANUALLY, ADJUST .env, AND RESTART DOCKER`)
|
||||
process.exit(-1)
|
||||
} finally {
|
||||
info(`Exiting process`)
|
||||
mainProcess.kill()
|
||||
|
@ -33,6 +33,11 @@ export const createPbClient = (url: string) => {
|
||||
client.admins.authWithPassword(email, password)
|
||||
)
|
||||
|
||||
const createFirstAdmin = safeCatch(
|
||||
`createFirstAdmin`,
|
||||
(email: string, password: string) => client.admins.create(email, password)
|
||||
)
|
||||
|
||||
const applySchema = safeCatch(
|
||||
`applySchema`,
|
||||
async (collections: Collection_Serialized[]) => {
|
||||
@ -50,6 +55,7 @@ export const createPbClient = (url: string) => {
|
||||
client,
|
||||
url,
|
||||
knex: rawDb,
|
||||
createFirstAdmin,
|
||||
adminAuthViaEmail,
|
||||
applySchema,
|
||||
...rpcApi,
|
||||
|
@ -5,20 +5,29 @@ import {
|
||||
PUBLIC_APP_DOMAIN,
|
||||
PUBLIC_APP_PROTOCOL,
|
||||
} from '$constants'
|
||||
import { schema } from '$src/migrate/schema'
|
||||
import { logger, mkSingleton } from '@pockethost/common'
|
||||
import { createPbClient } from './PbClient'
|
||||
|
||||
export const clientService = mkSingleton(async (url: string) => {
|
||||
const { dbg, error } = logger().create(`client singleton`)
|
||||
const client = createPbClient(url)
|
||||
|
||||
try {
|
||||
await client.applySchema(schema)
|
||||
|
||||
await client.adminAuthViaEmail(DAEMON_PB_USERNAME, DAEMON_PB_PASSWORD)
|
||||
dbg(`Logged in`)
|
||||
} catch (e) {
|
||||
error(
|
||||
`***WARNING*** CANNOT AUTHENTICATE TO ${PUBLIC_APP_PROTOCOL}://${PUBLIC_APP_DB}.${PUBLIC_APP_DOMAIN}/_/`
|
||||
)
|
||||
error(`***WARNING*** LOG IN MANUALLY, ADJUST .env, AND RESTART DOCKER`)
|
||||
try {
|
||||
await client.createFirstAdmin(DAEMON_PB_USERNAME, DAEMON_PB_PASSWORD)
|
||||
await client.adminAuthViaEmail(DAEMON_PB_USERNAME, DAEMON_PB_PASSWORD)
|
||||
} catch (e) {
|
||||
error(
|
||||
`***WARNING*** CANNOT AUTHENTICATE TO ${PUBLIC_APP_PROTOCOL}://${PUBLIC_APP_DB}.${PUBLIC_APP_DOMAIN}/_/`
|
||||
)
|
||||
process.exit(-1)
|
||||
}
|
||||
}
|
||||
return {
|
||||
client,
|
||||
|
Loading…
x
Reference in New Issue
Block a user