Skip to content

Conversation

@JeremieLeblanc
Copy link

Checks if the user was returned from the getUserInfo function before trying to create an account and login.

This allows us to do an extra verification step inside the getUserInfo function in the config file.

An example where this might be useful is when you only want to allow accounts from a specific google organization to login, this could now be achieved with the following:

getUserInfo: async (accessToken: string) => {
  const response = await fetch('https://www.googleapis.com/oauth2/v3/userinfo', {
    headers: { Authorization: `Bearer ${accessToken}` },
  });
  const user = await response.json();

  // Only allow users from a specific organization to login
  if (!user.hd || user.hd !== 'organization.com') return null;

  return { email: user.email, sub: user.sub };
},

Feel free to close this pull request if you do not feel like it is needed.

Checks if the user was returned from the getUserInfo function before trying to create an account and login.

This allows us to do an extra verification step inside the getUserInfo function in the config file.

An example where this might be useful is when you only want to allow accounts from a specific google organisation to login, this could now be achieved with the following:

```
getUserInfo: async (accessToken: string) => {
        const response = await fetch('https://www.googleapis.com/oauth2/v3/userinfo', {
          headers: { Authorization: `Bearer ${accessToken}` },
        });
        const user = await response.json();

        // Only allow users from specific organisation to login
        if (!user.hd || user.hd !== 'organisation.com') return null;

        return { email: user.email, sub: user.sub };
      },
```
Copy link
Owner

@WilsonLe WilsonLe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devs can simply throw an error while defining getUserInfo. Adding a null return type to the getUserInfo is not necessary IMO.

@JeremieLeblanc
Copy link
Author

Fair enough!

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 this pull request may close these issues.

2 participants