Feature request — Local API to programmatically log user in without password #2895
dtinth
started this conversation in
Feature Requests & Ideas
Replies: 2 comments
-
I need this too, working on it now |
Beta Was this translation helpful? Give feedback.
0 replies
-
I create a custom endpoint for this to force login with provided email
add config in payload.config.ts
reference from this plugin https://github.com/thgh/payload-plugin-oauth/blob/main/src/index.ts Then you can call it like this
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Feature request
It would be really great if payload had this API:
It would establish a cookie session just like
payload.login
, but it only takes just a user ID instead of a sign-in credentials.Why
This would make it easier to implement (i.e. duct-tape) additional auth features, such as letting people log in with their Google, Discord or GitHub account (e.g. using OAuth, OpenID Connect, etc) without having to deal with the intricacies of Payload’s internals (such as Passport.js) or advanced Payload features that are less well-documented.
Here’s how we may use it:
Current workaround
Right now, for the lack of API to programmatically log in, I work around by force-updating the user’s password and then do some client-side UI automation to log the user in with this new password.
I added a React component that would extract the params from the URL and submit the login form (like how a password manager does it).
Although it is very hacky, it accomplishes the task using only Payload’s well-documented API.
Feasibility
The logic required to implement this API already exists in the latter half of the
payload.login()
function:payload/src/auth/operations/login.ts
Lines 124 to 230 in 837dccc
…and duplicated in the
resetPassword()
function:payload/src/auth/operations/resetPassword.ts
Lines 84 to 120 in 837dccc
By extracting the common logic into an API, not only it becomes more straightforward to extend the auth system, there would also be less duplicate code in Payload’s core.
Beta Was this translation helpful? Give feedback.
All reactions