mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-09 22:52:58 +03:00
🚀 Feature: Api to get a user by username #126
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @elee1766 on GitHub.
Originally assigned to: @kmendell on GitHub.
Feature description
I would like an api endpoint to be able to get a user given a username exists.
Pitch
When developing an application that uses pocket-id, it may be advantageous to be able to get the user id, or even the user information, of a user given a username.
The username is already a unique field in the table - so it should be no more trouble than user by id.
this would be useful in applications that want to store things and control access by user_id as an underlying key, but to be able to reference that key through their username. This is useful because this means that a users storage, if keyed by their id, would stay with them seamlessly through migration, and also that there would be no issue where someone could access someone elses stuff when a username changed.
note that it's already possible to see if a username already exists through trying to create a user with the username.
@kmendell commented on GitHub:
Instead of a separate endpoint for this, you can use the existing
/api/users/endpoint which allows the client to filter by username by providing the "search" query param. Let me know if you would like an example. Otherwise you can refer to the API Documentation on how to do this.@elee1766 commented on GitHub:
fwiw, my use case for this is:
i would like to store documents for each user, i would like to store them by by their user_id so that i dont need to move their documents if they change their username, but i would like to access these documents by their username
but to do this, i have to store my own mapping of username <-> user_id.
it would be really helpful therefore instead of trying to sync this data in my local database to just hit pocket id, to get the user_id, and also would allow me to check sub against user_id for authenticated requests.