🚀 Feature: Api to get a user by username #126

Closed
opened 2025-10-09 16:27:48 +03:00 by OVERLORD · 2 comments
Owner

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.

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.
Author
Owner

@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.

@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.
Author
Owner

@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.

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pocket-id-pocket-id-2#126