Skip to content
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

CouchDBUser.create() fails if require_valid_user = true #13

Open
vweyl opened this issue May 3, 2013 · 0 comments
Open

CouchDBUser.create() fails if require_valid_user = true #13

vweyl opened this issue May 3, 2013 · 0 comments

Comments

@vweyl
Copy link

vweyl commented May 3, 2013

Currently to create a new user using the CouchDBUser module, it simply puts a new document in the _users database using a standard sync request (this.load()).

It won't work if CouchDB is configured to expect a valid user and there is no configuration option to pass admin parameters (or any valid user) to CouchDBUser.

My workaround to make it work is to manually rewrite the create method of CouchDBUser and pass it the admin credentials:

this.create = function create() {
var promise = new Promise,
user = this;

        if (!this.get("type")) {
            this.set("type", "user");
        }

        if (!this.get("roles")) {
            this.set("roles", []);
        }

        this.getTransport().request("CouchDB", {
                            method: "PUT",
                            path: "/_users/org.couchdb.user:"+ user.get("name"),
                            auth: cdbAdminCredentials,
                            headers: {
                                    "Content-Type": "application/json",
                                    "Connection": "close"
                            },
                            data: user.toJSON()
                            }, function (result) {
                                    var json = JSON.parse(result);
                                    if (json.ok) {
                                            promise.fulfill();
                                    }
                                    else {
                                            promise.reject(json);
                                    }
                            });
                    return promise;
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant