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

Feature for updating user info on signin #22

Closed
augustgaukstad opened this issue May 10, 2024 · 4 comments · May be fixed by #23
Closed

Feature for updating user info on signin #22

augustgaukstad opened this issue May 10, 2024 · 4 comments · May be fixed by #23

Comments

@augustgaukstad
Copy link

I have a case where I would love it if my Payload-users get updated data when they sign in.

Currently got a flow for this working locally like this:

if (users.docs && users.docs.length) {
    user = users.docs[0];
    user = await payload.update({
        collection: collectionSlug,
        id: user.id,
        data: info,
        showHiddenFields: true,
    })
    user.collection = collectionSlug;
    user._strategy = 'oauth2';
}

The info contains up to date data fetched through the authorization flow.

Tried cloning the repo and replicating my code, but getting a type-error on this line:
id: user.id

Error:
Property 'id' does not exist on type 'User & { collection?: any; _strategy?: any; }'.

Guessing it's because there actually isn't a User collection with values being referenced? Tried addind id: number to the User interface, but that creates a whole bunch of other type issues.

If anyone has any ideas on how to make this work I think it'd be a great addition to the plugin :)

@thgh
Copy link
Owner

thgh commented May 13, 2024

Looks like the type expects id: string | number which doesn't error

-interface User {}
+interface User { id: string | number }

interface User {}

@augustgaukstad
Copy link
Author

augustgaukstad commented May 14, 2024

Thanks! That did the trick.

I'm trying to follow the contribution guide from the readme, but don't seem to have access to push to this repo. VSCode suggests creating a fork and pushing to that, is that the correct workflow? First time contributing to someone else's repo, sorry for the noobyness :)

Edit: i did create a new branch for the feature btw, assumed that would be best practice

@thgh
Copy link
Owner

thgh commented May 14, 2024

Congrats on your first contribution (in progress) 😛

Yes, typically one follows these steps:

  1. Fork the repo: https://github.com/thgh/payload-plugin-oauth/fork
  2. Clone the fork
  3. Commit & push changes to the fork
  4. Then a pull request button appears over here: https://github.com/thgh/payload-plugin-oauth/pulls

@thgh
Copy link
Owner

thgh commented May 15, 2024

Another tip: you can write "Resolve #22" in the PR message, which will tell Github to close this issue after the PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants