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

Auth hooks updates signed access_token, but not REST response. #1415

Closed
2 tasks done
mr-menno opened this issue Feb 10, 2024 · 12 comments
Closed
2 tasks done

Auth hooks updates signed access_token, but not REST response. #1415

mr-menno opened this issue Feb 10, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@mr-menno
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

user_metadata in access token does not match user_metadata in REST response.

To Reproduce

Create auth hook in Supabase to update user_metadata.

  1. access_token JWT contains updated user metadata.
  2. REST response JSON including the access_token misses data in user.user_metadata.

Expected behavior

Consistency between REST response and access_token.

Other Issue

Gotrue-js issue:

supabase/auth-js#852

System information

  • Version of supabase-js: 2.39.3
  • Version of Node.js: 20
@mr-menno mr-menno added the bug Something isn't working label Feb 10, 2024
@J0
Copy link
Contributor

J0 commented Feb 13, 2024

Hey!

Thanks for the query. getSession typically checks for a local token which might be out of sync with the recently returned token. If you're looking to obtain an up to date token with custom claims would recommend that you update app_metadata in the Auth Hook and use getUser to obtain a fresh access token.

Alternatively, you could wait for a refresh event to happen and the new access token should show the claims, providing they were saved to the users table.

Hope this helps

@mr-menno
Copy link
Author

mr-menno commented Feb 13, 2024 via email

@J0
Copy link
Contributor

J0 commented Feb 14, 2024

Hey @mr-menno,

Sorry, I spoke with a colleague earlier today who and realized that I misunderstood this query. The REST response indeed does not return the claim but the signed access token does. We'll likely add it in the REST response for the next release

Thanks for flagging this!

@taytzehao
Copy link

would like to take this

@mr-menno
Copy link
Author

mr-menno commented Feb 16, 2024 via email

@taytzehao
Copy link

@mr-menno , could you show a precise example of it? Currently, when I run

const { data2, error2 } = await supabase.auth.updateUser({
    data: { hello: 'world5' }
  })

data2 is undefined. Do you mean this?

@mr-menno
Copy link
Author

mr-menno commented Feb 20, 2024 via email

@tzehaoo
Copy link

tzehaoo commented Feb 27, 2024

okay, creating the PR

@hf
Copy link
Contributor

hf commented Mar 18, 2024

Custom Access Token Hook cannot be used to modify the user metadata, which is common with other similar features in other authentication software. There will be a different hook in the future where you could change the user metadata "before sign up" for example.

@hf hf closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2024
@mr-menno
Copy link
Author

mr-menno commented Mar 18, 2024 via email

@serhii-kucherenko
Copy link

same here

@imbhargav5
Copy link

Same issue on our end too. The hook updates the access token,but the resultant json ignores it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants