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

typed or generic useFusionAuth #94

Closed
kasir-barati opened this issue May 12, 2024 · 13 comments · Fixed by #136
Closed

typed or generic useFusionAuth #94

kasir-barati opened this issue May 12, 2024 · 13 comments · Fixed by #136
Assignees
Labels
DX enhancement New feature or request React

Comments

@kasir-barati
Copy link

kasir-barati commented May 12, 2024

Typed/generic useFusionAuth hook

Problem

I'm always frustrated when I am using useFusionAuth hook. It is really cumbersome to create a custom hook just because the one exported from lib is not typed. I mean its user is not typed.

Solution

I love to have something like this:

import { useFusionAuth } from '@fusionauth/react-sdk';

const { user } = useFusionAuth();
user. // now it should show me a list of available properties; given_name, picture, etc

or

export interface DecodedIdToken {
  // ...
  family_name: string;
  // ...
}

const { user } = useFusionAuth<DecodedIdToken>();
user.family_name; // it should be typed

Alternatives/workarounds

create a custom hook.

Community guidelines

All issues filed in this repository must abide by the FusionAuth community guidelines.

How to vote

Please give us a thumbs up or thumbs down as a reaction to help us prioritize this feature. Feel free to comment if you have a particular need or comment on how this feature should work.

@kasir-barati kasir-barati added the enhancement New feature or request label May 12, 2024
@JakeLo123
Copy link
Collaborator

JakeLo123 commented May 13, 2024

What version of the package produces this?

It ought to be typed--renamed to userInfo since v2.0.

image

@kasir-barati
Copy link
Author

hmm, "@fusionauth/react-sdk": "^1.0.6". But thanks for the heads up. I upgraded it by executing npm i @fusionauth/react-sdk@2.1.1.

@kasir-barati
Copy link
Author

kasir-barati commented May 13, 2024

I see a lot of improvements already by upgrading it. BTW where are the custom user data? or preferred_username for that matter.

@kasir-barati
Copy link
Author

BTW I also saw that /app/me should return user info according to server requirements. But then we have this GH issue for FusionAuth Typescript client. Maybe you can help me to see the full picture.

Thanks in advance.

@JakeLo123
Copy link
Collaborator

BTW I also saw that /app/me should return user info according to server requirements. But then we have this GH issue for FusionAuth Typescript client. Maybe you can help me to see the full picture.

Thanks in advance.

I'm not sure how that GH issue is related to this package? The SDK's /app/me endpoint is a wrapper around fusionauth the /oauth2/userinfo endpoint. That type of userinfo response is an OIDC standard.

You may have already looked here, but the "User Info" section of this page for the GET /oauth2/userinfo endpoint has more specifics. I hope that helps!

@kasir-barati
Copy link
Author

I'm not sure how that GH issue is related to this package? The SDK's /app/me endpoint is a wrapper around fusionauth the /oauth2/userinfo endpoint. That type of userinfo response is an OIDC standard.

It is related, because that is what is written in here as server requirements and I am using @fusionauth/typescript-client
which is a simple wrapper, making it easier for us to communicate with the FusionAuth RESTful API.

So what I am trying to convey is that in @fusionauth/typescript-client we do not have a typed response as it is stated in the aforementioned GH issue. But we can ignore this comment of mine. I was just trying to have a better understanding of the situation.

You may have already looked here, but the "User Info" section of this page for the GET /oauth2/userinfo endpoint has more specifics. I hope that helps!

Yes, I read it. There I saw preferred_username, and then I asked the inevitable question: why it is not part of the userInfo since it is in the OpenID specification: https://openid.net/specs/openid-connect-core-1_0.html#UserInfo

Or am I mistaken?

@JakeLo123
Copy link
Collaborator

Yes, I read it. There I saw preferred_username, and then I asked the inevitable question: why it is not part of the userInfo since it is in the OpenID specification: https://openid.net/specs/openid-connect-core-1_0.html#UserInfo

I think you are right about that. preferred_username is not specified on the UserInfo type that we've defined here, although it is part of the response. Let's add it.

@JakeLo123
Copy link
Collaborator

Added this ticket here. #95
Thank you for pointing this out @kasir-barati!

@kasir-barati
Copy link
Author

@JakeLo123 just a thought, do you think we could make useFusionAuth to accept a generic type. Just in case someone wanted to return a bit more info in their /app/me endpoint. Or something none-standard.

@JakeLo123
Copy link
Collaborator

That certainly sounds possible. That could be a nice enhancement if using a custom /app/me endpoint.

Reopening this 👍

@JakeLo123 JakeLo123 reopened this May 14, 2024
@linear linear bot added the DX label Jun 14, 2024
@michaelyons michaelyons self-assigned this Jun 17, 2024
@michaelyons
Copy link
Collaborator

@kasir-barati! do you have a issue that would be solved by adding a generic to the FusionAuthProvider?

@kasir-barati
Copy link
Author

Yes, you could put it that way too. I have my own custom backend app. and let's say my /app/me will return a bunch of additional data attached to your normal standard response that this endpoint should return. So I would really love saying to this SDK that my User interface is a bit different.

@JakeLo123 JakeLo123 self-assigned this Jun 20, 2024
@JakeLo123 JakeLo123 mentioned this issue Jun 20, 2024
1 task
@JakeLo123 JakeLo123 linked a pull request Jun 20, 2024 that will close this issue
1 task
@JakeLo123
Copy link
Collaborator

JakeLo123 commented Jun 20, 2024

#136 PR is up now and this should come out in with the next SDK version 2.3.0. Thank you for your suggestion @kasir-barati -- we do want to support custom server implementations, so this was definitely needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX enhancement New feature or request React
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants