I have a question regarding the design of the sign-up procedure using FeatherJS for the back-end of my application.
The problem I'm facing is the following:
I want a user to be able to sign-up his organisation/company using his/her email and a password. This user can be considered as the administrator of the organisation.
When that admin user has been created I want that same user to be able to create additional users that are linked to his/her organisation. To ensure that only the admin user can create additional users I've set up feathers-permission to check for 'admin' rights in the "before" hook of the "Users" service
module.exports = {
before: {
all: [ ],
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ authenticate('jwt'), checkPermissions({
roles: [ 'admin' ]
}), hashPassword ],
update: [ authenticate('jwt'), checkPermissions({
roles: [ 'admin' ]
}), hashPassword ],
patch: [ authenticate('jwt'), checkPermissions({
roles: [ 'admin' ]
}), hashPassword ],
remove: [ authenticate('jwt'), checkPermissions({
roles: [ 'admin' ]
}) ]
},
The issue that I am encountering now is that I cannot sign-up the initial user because the before hook is requesting an authenticated user that has admin rights which I don't have because that user hasn't been created yet.
I could remove the authentication and permissions check but then I leave my User service "unprotected" and anyone would be able to create a user using the right POST call to the server.
The question I have is: How should I setup my service and/or hooks so that I can sign-up a new user in my application and that only that authenticated admin user can create new users in the application?
Many thanks in advance!