2
votes

First, let me say that i am just learning the basics of backend using Cloudant. I need to develop an iOS app that allows the users to create an account and login into the app, but i am a little confuse with this process. I have read the Cloudant Authenticate Docs but it looks like that information is related to creating admin users to access the database, not the target users of the app. So i was thinking that what i have to do is:

  1. Create a "createAccount" web service -> This web service will create a document in my Cloudant database. I would use a "type" field in the document and set it to "user" (Because in Cloudant i can not have collections, so one way to differentiate types of documents is by adding a "type" field).

  2. Create a "login" web service -> I would need to do some logic here to authenticate the user and return a cookie for future use in all the web services.

So basically my questions are:

  1. Is this a valid way to create users documents in Cloudant?
  2. If not, what could you recommend me?
  3. How can i define that some documents (for example, a document that represents a post) should only be modified by a certain user? Maybe having some info about the user inside the post document?
  4. Will the Authenticate APIs that Cloudant has built-in work for this case?

Thanks a lot for your help!

1

1 Answers

1
votes

From your use-case I think you should look at using API keys and the one database per user model. The gets around the need for a web service to restrict what the application can view.

So what your application would do is.

  1. Sign up -> Web Service -> creates a new database -> generates set of API keys for that database, which is returned to the user.

  2. Log-in -> generates a new set of API keys for that instance of the application.

There is an example of creating a web service to handle the sign-up part here