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

docs: Provide sample code for handling Handle #2544

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

paulproteus
Copy link
Collaborator

This takes a recommendation from @kentonv 's recent conversation on sandstorm-dev and adds a link to @dwrensha 's GitLab code.

Review requested from at least one of:

I'm willing to continue to make changes this, or use other people's preferred text, as needed.

@kentonv
Copy link
Member

kentonv commented Sep 14, 2016

This recommendation only applies when packaging apps that are already coded around the assumption of a username that is a primary key. For new code I would recommend avoiding usernames as a primary key.

@paulproteus
Copy link
Collaborator Author

OK @kentonv how about now? :)

* **Our recommendation on how to use this:** If you need a unique identifier, use the
`X-Sandstorm-User-Id`. If your app requires that handles also be unique, then use the
following algorithm. If there is already an account for the user ID, don't change its
handle. If another account exists with the same handle, then append some numbers to make the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this algorithm description is in the uncanny valley between precise and informal. How about:

If your app requires that handles be unique -- for example, because the app is designed to use "usernames" as the primary user identifier -- then you will need to track and store those handles in your app's storage. We suggest implementing the following algorithm, for each request:
1. If there is already a user account in your app's database associated with the request's `X-Sandstorm-User-Id`, use the handle associated with it.
2. Otherwise, if no existing user account is already associated with `X-Sandstorm-Preferred-Handle`, create a new account for this user's ID and handle, and use that.
3. Otherwise, this is a new user but their handle is already in use. Append a number to the handle such that it is unique, create a user account using the user's ID and the modified handle, and use that.

@ocdtrekkie ocdtrekkie added the documentation Documentation issues label Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants