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

fix/supabase version 1 #1474

Closed
wants to merge 77 commits into from

Conversation

duncanhealy
Copy link

@dthyresson
Copy link
Contributor

dthyresson commented Nov 16, 2020

@Tobbe and I realized tonight that perhaps something changed in the Supabase API that may now require a custom decoder to extract the currentUser info on the API side.

see:

export const getCurrentUser = async (decoded, { _token, _type }) => {

export const getCurrentUser = async (decoded, { _token, _type }) => {
  return { ...decoded, roles: parseJWT({ decoded }).roles }
}

It is "spreading" the JWT into chars -- and not sure if it did that in the past.

This might mean that supabase should get its own decoder similar to what is done for Netlify Identity:

https://github.com/redwoodjs/redwood/blob/main/packages/api/src/auth/decoders/netlify.ts

where is

jwt.decode(token)

so that currentUser will have the decoded version of it.

Note: this does not verify the accessToken, though it probably should ... to check for expiry against the secret --- which would be then a required env.

@dthyresson dthyresson linked an issue Nov 16, 2020 that may be closed by this pull request
@duncanhealy duncanhealy marked this pull request as draft November 17, 2020 09:53
@kiwicopple
Copy link

thanks for the tag @viperfx.

I just released the new version of gotrue-js to include @duncanhealy's commit , then bumped the version in supabase-js.

The draft supabase.ts just has a mockup of the types - not sure if it is correct

Let me know if that's all you need here, otherwise I can jump in and figure out the types. I did actually start on this but I'm swamped with our beta launch - thanks the patience 🙏

@viperfx
Copy link
Contributor

viperfx commented Dec 1, 2020

Thanks @kiwicopple

Look forward to these changes @duncanhealy

Let me know if you need help testing.

@duncanhealy
Copy link
Author

I'm getting null back for the user object from the graphql endpoint after logging in

{"data":{"redwood":{"currentUser":{"0":"n","1":"u","2":"l","3":"l","roles":[]}}}}

looking at local dev -> might be because of this

changing typesToDecoders.supabase to netlify

with that change I get back -

{"data":{"redwood":{"currentUser":{"roles":[]}}}}

@dthyresson
Copy link
Contributor

might be because of this

Hi @duncanhealy you may need to implement a decoder for supabase.

I do not think using the netlify decoder is 100% correct, because it relies on the Identity feature of Netlify to place a decoded and populated user in the context in production --- and that the token is decoded in in dev.

What is supabase setting as the token in

export const decodeToken = async (

?

Based on that will need to determine how the decode it if needed.

@Tobbe
Copy link
Member

Tobbe commented Dec 2, 2020

@duncanhealy Thanks for getting the ball rolling on this! Your work both here and over in the supabase repo(s) is much appreciated ⭐

I went ahead and upgraded to Supabase 1.0 over here #1536 and that PR has now been merged.

@Tobbe Tobbe closed this Dec 2, 2020
@Tobbe
Copy link
Member

Tobbe commented Dec 2, 2020

@kiwicopple I did the upgrade from scratch over in #1536 and so I wanted to ask if you could please take a look at the type imports. More details over in that PR.

@duncanhealy duncanhealy deleted the fix/supabase_version_1 branch December 2, 2020 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade Supabase in auth package to supabase-js version 1.0