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

Documentation on getIdentityFromAccount #8

Open
dnk8n opened this issue Aug 1, 2023 · 2 comments
Open

Documentation on getIdentityFromAccount #8

dnk8n opened this issue Aug 1, 2023 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@dnk8n
Copy link

dnk8n commented Aug 1, 2023

From what I understand, passing a function as getIdentityFromAccount to msalAuthProvider, from this library, sets an identity object which can later be referenced. Am I right in that assessment? If so, how do we reference what we set downstream?

For example, in getIdentityFromAccount function, could I call my API once to get extra database attributes, so that these don't have to be managed separately or repeatedly called, e.g. employee ID (in my database, employee IDs are different to user IDs, which are the same as in Active Directory).

My intended use case is to pass this value to dropdowns, so that logged in user's preferences are prioritized to the top (this I know how to do, and am currently needing to save details to localStorage, which I think by using this feature I can avoid).

@dnk8n
Copy link
Author

dnk8n commented Aug 1, 2023

As usual, I have an Aha moment right after posting the question.

I think I understand, but maybe to less experienced React users like me, it could be made a bit more explicit (maybe just a mention/link to the appropriate docs for react-admin).

What I understand is that instead of passing, as I have done:

const baseAuthProvider = msalAuthProvider({
  msalInstance,
  loginRequest,
  tokenRequest,
  redirectOnCheckAuth: true,
});

export const authProvider = {
  ...baseAuthProvider,
  getPermissions: async () => { ... },
  getIdentity: async () => {
    return await getEmployeeProfile();
  },
};

I can do this, and it results in the same effect:

export const authProvider = msalAuthProvider({
  msalInstance,
  loginRequest,
  tokenRequest,
  getPermissionsFromAccount: async () => { ... },
  getIdentityFromAccount: async () => {
    return await getEmployeeProfile();
  }
  redirectOnCheckAuth: true,
});

I therefore retrieve these attributes via React-Admin's useGetIdentity.

If there is nothing extra to add, I guess this can be closed. A very experienced user would have made the connection immediately.

@slax57
Copy link
Collaborator

slax57 commented Aug 21, 2023

Once again thank you for your feedback, and sorry for the delay of our answer (holidays... 🌴 😇 )

I guess we could add a line in the doc explaining that the result of the getIdentityFromAccount function can later be accessed with RA's useGetIdentity.

Same goes for the getPermissionsFromAccount function, for which the provided example does not really show how to use the different permissions.

I'll mark this as a documentation issue.

@slax57 slax57 added the documentation Improvements or additions to documentation label Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants