Comments (10)
Non-interactive cli execution seems to be a common request (#29).
In that case, I'll consider removing the initial admin create interactions and will replace them with a "Installer" web page.
In the meantime, I'm not sure what your use case with Docker is, but often tasks that need to be executed only once could be performed inside a DB migration - https://pocketbase.io/docs/db-migrations/.
from pocketbase.
@krushiraj If you have the time, feel free to pick it.
I was planning to work on it some time during the next week (or the week following it). Here are some suggestions about the implementation:
- add a healthcheck endpoint that could return some json map that has a property
installed
,readyToUse
,hasAdmin
or something along the line that will betrue
if we have at least one admin, orfalse
otherwise (need tests) - change the admin apis create handler to accept guest submits when there aren't any admins (need tests)
- update the js-sdk package to have the new healthcheck endpoint (need tests)
- on the frontend when initilizing the web page add a call to the healthendoint and if the map value is false show the installer page (could also store the healthcheck result in localstorage to prevent calling it on each page refresh)
from pocketbase.
No issues :).
I can give it a try and draft a PR. I will mention it here once I’m done.
from pocketbase.
Okay. I actually though of going with the later approach to redirect to register admin when there are no admins.
from pocketbase.
In the meantime, I'm not sure what your use case with Docker is, but often tasks that need to be executed only once could be performed inside a DB migration - https://pocketbase.io/docs/db-migrations/.
In Docker/Kubernetes it's common to pull the default account information from a secret when bootstrapping a new service. The usual pattern is to provide a combination of environment variables allowing the consumer to pass either the value, or the path to a file containing the value.
For example, PostgreSQL has environment variables for POSTGRES_PASSWORD and POSTGRES_PASSWORD_FILE
I've found a handy pattern in Go is to accept these as arguments to a CLI command, instead of reading the environment variables directly. Then anyone using it in a container can run CLI commands in an initContainer or entrypoint script.
Another example is Keycloak, which provides a CLI for managing users that is easy to script.
I'm interested in implementing this feature if it sounds good to you.
from pocketbase.
@wilj As mentioned in the closed PR #29 - for PocketBase always providing an admin email and password as flags or env variables doesn't make sense, because this is required only when you start the application for the first time (aka. when you don't even have a database file).
One time operation should be done with DB migrations (its practically the same when you want to seed or change the schema of your database).
Alternative and more easier approach, compared to the "Installer" web page, could be to provide a separate command create-admin
that will have to be executed before starting the server, but that's not very user friendly.
from pocketbase.
Actually my point of creating that PR was to provide email and password for admin in a way so that in one off scripts we can easily set first admin details.
The migrations method you suggested is good but problem with that is we can’t use that with the binary that is released. Hence we must clone repo and add code to migrations file and add it. Which is complex than having a support to add new admin via CLI or web page.
Also, the suggestion you gave on #29 doesn’t seem to work.
Currently I have a work around. I locally created an admin by interacting with cli and copied pb_data directory. So I know I would have a new set of default email and password for that instance. Then I create a new admin and delete the default one.
PS: This comment is just to give idea on how to host it easily using docker. https://github.com/krushiraj/pocketbase-docker (I know I cloned the repo in this docker solution, that is because I see errors while running the binary. Used amd64/ubuntu
and download adm64 binary. But I still get exec format error, which usually is an error when the architecture of compilation is different)
from pocketbase.
@krushiraj Thanks for clarifying. Sorry for the non-working example. I didn't tested it. It doesn't work because we outputing other things to the stdout.
But anyway, adding a new "Installer" page will remove the cli interactivity and resolve the issue.
from pocketbase.
@krushiraj I'll assign the issue to me and will start working on that tomorrow. Actually I think it could be implemented even easier, without the healthcheck endpoint, by adding a middleware to the ui file serving handlers that will always redirect to the installer page when there is no admin (the query will be done outside of the handlers).
from pocketbase.
The new Installer page was added in the v0.2.0 release.
The implementation ended up a little more complicated and hacky than I initially though, because we are using client-side fragment navigation for the admin UI (aka. /#/...
) and the path is not visible on the server-side and therefore a special installer
query parameter was introduced.
Please report if you stumble on something or it doesn't work as expected.
from pocketbase.
Related Issues (20)
- cronRemove cannot be called from inside a job in JavaScript HOT 2
- `$os.readFile` and `$os.getwd` use `/` as working directory in production enviroment HOT 4
- Feature Request: is there is any way to make our own Custome storage system. HOT 1
- Proposal: Switch to LumoSQL HOT 1
- Issue with Hour Field Not Triggering in CronJob Registration HOT 1
- Querying Auth Record from a PB Hook does not return the email field, if the user has emailVisibility set to false HOT 1
- Extending with JS: Object access within DynamicModel not ergonomic? HOT 2
- How to expand ModelQuery results?
- JSON fields not showing in admin item drill-down HOT 2
- Problem with operator: `?=` HOT 2
- Admin interface loads slowly because of the created field HOT 1
- How can I filter a date using the equal = operator ? HOT 2
- Is it possible to clear out all records leaving the structure intact?
- Proposal: Add a POST log's route HOT 3
- Is it possible to override default console output
- Proposal: automatically load custom certificates from /pb_certificates HOT 1
- [Feature] Add a 'Duplicate' option to the selected record in the Admin UI HOT 1
- Feature Request: RSA Token/ minting record in token for M2M auth HOT 1
- Incorrect file name mangling with dual extensions files HOT 3
- Cross joins not working in view collections HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pocketbase.