mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-25 15:06:01 +00:00
chore(auto-admin): plugin.ts
This commit is contained in:
parent
7b8248a486
commit
b2d33cfdbb
@ -1,30 +1,3 @@
|
||||
import PocketBase from 'pocketbase'
|
||||
import {
|
||||
PocketHostPlugin,
|
||||
onAfterInstanceStartedAction,
|
||||
parseError,
|
||||
} from 'pockethost'
|
||||
import { LOGIN, PASSWORD, PLUGIN_NAME } from './constants'
|
||||
import { dbg, info } from './log'
|
||||
|
||||
const plugin: PocketHostPlugin = async ({}) => {
|
||||
dbg(`initializing ${PLUGIN_NAME}`)
|
||||
|
||||
onAfterInstanceStartedAction(async ({ instance, url }) => {
|
||||
const { subdomain } = instance
|
||||
dbg(`launched instance ${instance.subdomain} on ${url}`)
|
||||
const client = new PocketBase(url)
|
||||
const email = LOGIN()
|
||||
const password = PASSWORD()
|
||||
try {
|
||||
await client.admins.create({ email, password, passwordConfirm: password })
|
||||
dbg(`Admin account created`)
|
||||
} catch (e: any) {
|
||||
dbg(`Failed to create admin account: ${parseError(e)} `)
|
||||
} finally {
|
||||
info(`Default admin login for ${subdomain} is ${email}/${password}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
import { plugin } from './plugin'
|
||||
|
||||
export default plugin
|
||||
|
||||
28
packages/plugin-auto-admin/src/plugin.ts
Normal file
28
packages/plugin-auto-admin/src/plugin.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import PocketBase from 'pocketbase'
|
||||
import {
|
||||
PocketHostPlugin,
|
||||
onAfterInstanceStartedAction,
|
||||
parseError,
|
||||
} from 'pockethost'
|
||||
import { LOGIN, PASSWORD, PLUGIN_NAME } from './constants'
|
||||
import { dbg, info } from './log'
|
||||
|
||||
export const plugin: PocketHostPlugin = async ({}) => {
|
||||
dbg(`initializing ${PLUGIN_NAME}`)
|
||||
|
||||
onAfterInstanceStartedAction(async ({ instance, url }) => {
|
||||
const { subdomain } = instance
|
||||
dbg(`launched instance ${instance.subdomain} on ${url}`)
|
||||
const client = new PocketBase(url)
|
||||
const email = LOGIN()
|
||||
const password = PASSWORD()
|
||||
try {
|
||||
await client.admins.create({ email, password, passwordConfirm: password })
|
||||
dbg(`Admin account created`)
|
||||
} catch (e: any) {
|
||||
dbg(`Failed to create admin account: ${parseError(e)} `)
|
||||
} finally {
|
||||
info(`Default admin login for ${subdomain} is ${email}/${password}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user