Ojonugwa Jude Ochalifu
Ojonugwa Jude Ochalifu

Reputation: 27237

Using the User API with Google Cloud Endpoint

I successfully created a Google Cloud Endpoint backend module for my Android app and I am able to write, read and delete entites.But I have one problem, I want users of my app to be uniquely identified and to store individual entities independent of the other.For example, when User A logs in, and saves an entity, it should be independent of what User B saves. With each user being able to perform CRUD operations on their independent data in the datastore without affecting the other's. I know this can be possible with the help of the User class from Google's User's API but I have to clue on how to implement it.

Right now, this is how am making an Insert request:

/**
 * Inserts a new {@code ToDo}.
 */
@ApiMethod(
        name = "insert",
        path = "todo",
        httpMethod = ApiMethod.HttpMethod.POST)
public ToDo insert(ToDo todo) {

    ofy().save().entity(todo).now();
    logger.info("Created ToDo with ID: " + todo.getEmpId());

    return ofy().load().entity(todo).now();
}

When someone stores a todo, it should be available only to them.My app authenticates users using Google+ login

Upvotes: 2

Views: 98

Answers (1)

jirungaray
jirungaray

Reputation: 1674

In order to user the user API just add a parameter of the type com.google.appengine.api.users.User , and GAE will inject the corresponding user fetched using the users API (or null if not logged in ) you can read more info about it here.

It seems however that what you actually want to do is implement a multitenancy app using different namespaces for different users, check this documentation which explains how to set a namespace for each user and therefore prevent users from accesing each other's data.

Upvotes: 1

Related Questions