question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set role/metadata on initial call to /invite

See original GitHub issue

Our application programmatically invites users (on Netlify Functions) following the example in the documentation.

However, if we send a payload that includes app_metadata while inviting a user (e.g. {email: test@example.com, app_metadata: {roles: ['admin']}}), the user test@example.com gets successfully created but any app_metadata is ignored.

Is it possible to set the role/app_metadata directly in the initial call to create the user? I realize it’s possible to update the user in a separate followup API call but I’d like to limit requests if possible.

Is this supported? Not sure if I’m using the API correctly and/or this might be a bug since the API response example in the documentation seems to suggest it might be possible to set roles directly in the initial call.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
futuregeraldcommented, May 24, 2019

Hi @DavidChouinard , the user has to exist before you can add a role. If I were you I’d create a webhook that fires on signup or validation that assigns the role. It can be similar to what @shortdiv is doing in her example: https://github.com/shortdiv/identity-with-role-based-access/blob/master/src/lambda/handle-signup.js

1reaction
shortdivcommented, May 22, 2019

Hey @DavidChouinard, generally, email is saved under user_metadata, so you could do something like this:

    const identity = context.clientContext.identity;
    ...
    const inviteUrl = `${identity.url}/invite`;
    const adminAuthHeader = "Bearer " + identity.token;

    const response = await fetch(inviteUrl, {
      method: "POST",
      headers: { Authorization: adminAuthHeader },
      body: JSON.stringify({
        user_metadata: {
          ...event.body.user.user_metadata,
          email: customer.email,
        },
        app_metadata: {  roles: ["admin"] }
      })
    });

You can see an example of this in a function here, which shows how to add extra metadata to a user during the sign up flow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating and managing custom roles - IAM - Google Cloud
Role metadata includes the role ID and permissions contained in the role. You can view the metadata using the Google Cloud console or...
Read more >
How to Use Ansible Roles to Abstract your Infrastructure ...
First, let's create an Apache directory for our role and populate it with the required directories: mkdir apache; cd apache. Next we'll create ......
Read more >
Teleport Authorization | Teleport Docs
Every local Teleport User must be associated with a list of one or more roles. This list is called "role mappings". Non-interactive users....
Read more >
Ansible Playbook: ERROR! 'command' is not a valid attribute ...
The reason I ask is because the offending line appears to be 4, your hosts declaration. Looking at man page for ansible run ......
Read more >
Configuring App Metadata for Linked Roles - Discord
Apps must also set up an OAuth2 flow to allow users to authenticate and grant ... The first thing we'll do is create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found