-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DISCUSSION] feat: allow server-side modification of user doc on account creation #143
base: master
Are you sure you want to change the base?
Conversation
When you use |
@gr2m I’m using the hoodie-account-client as well. |
I could pass these things in from before hoodie-account-client, but I can’t trust the client about these things. |
Ah, what you need is a hook like One idea would be to see how hapi is doing it with their request lifecycle. We also had a discussion about a hook dream API here: hoodiehq/hoodie-client#42, which might work for your use case as well. tl;dr;
|
just an idea for a workaround, you could maybe use https://github.com/pouchdb/pouchdb-wrappers to wrap the PouchDB instance that you pass to hoodie-account-server? |
I like the idea of hooks and other things, but I’ve now realised, that the information I’m storing is only available at request-time (e.g. |
049056c
to
dc69e68
Compare
well that’s embarrassing 😳 here’s a version that does that :D, so my stuff can be made to work (squashed and force pushed) |
|
||
if (hooks.account && hooks.account.beforeAdd && | ||
typeof hooks.account.beforeAdd === 'function') { | ||
doc = hooks.account.beforeAdd(doc, request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we’d make this a util
of course
The doc I want to augment is created in |
We had a discussion on this and will see if we can use the custom "signup" route handler for this. This feature is not yet implemented. The idea is that besides custom requests that can be passed as on object to the |
@janl we now use before-after-hook at several places in Hoodie. I think that could fit perfectly with your initial requirement
We could for example expose an server.plugins.account.api.hook.before('add', function (properties) {
properties.roles.push('mycustomrole')
})
server.register({
register: hapiAccount,
options: {
// other options
hooks: {
add: {
before: function (properties) { properties.roles.push('mycustomrole') }
}
}
}
}, function (error) {
if (error) {
throw error
}
// plugin account api, see below
}); Would that be helpful for your use case? |
Heya, I’m using this outside of Hoodie and I found the need to be able to change the user doc on account creation.
E.g. I need to add another role to the user doc, and the server will know which one.
My idea was to add a function, for illustration purposes called
userDocModificationFun
(please bikeshed), to pass into the plugin options, and then, if that function exists, it gets called onaccount.add()
. In order to support this, the top level options object needs to be passed down toaccount.add()
(which looks like was planned anyway, this adds the plumbing).Please let me know if this is an acceptable addition. If yes, I’m happy to add tests and clean things up.