marmelab / ra-supabase

Supabase adapter for react-admin, the frontend framework for building admin applications on top of REST/GraphQL services.
MIT License
156 stars 27 forks source link

support redirectTo in SupabaseAuthProviderOptions #39

Closed joel-gfdez closed 1 year ago

joel-gfdez commented 1 year ago

I did some stuff wrong, sorry and please ignore this

~Thanks in advance for all your work, first of all. I am submitting these changes in order to achieve a specific behavior regarding redirect URLs that I think should be supported by this package.~

~Summary~

~Support the use of redirectTo option in supabase client to use custom redirect URLs after signing in with OAuth providers. The same redirectTo property in supabaseAuthProvider arguments works for Set and Reset password flows.~

~Problem~

~This is the case I was dealing with:~

~If all of these conditions are true, the react-admin authentication provider will fail to complete the authentication flow, since the access and refresh tokens never get to the Admin component as expected. Since the supabase client uses the SITE_URL by default, and the customer authentication flow needs it to be set to the root URL of the web application, it is impossible to use an alternative authentication flow using ra-supabase, as it will try to redirect to the root URL instead of the custom admin URL.~

~Solution~

~Allowing the developer to set an additional string property redirectTo in SupabaseAuthProviderOptions and using its value as a parameter when calling signInWithOAuth, as it is described in the Supabase documentation.~

~Additionally, the same value can be used to achieve this behavior in the set-password flow.~

~Notes~

~Feel free to leave a comment if you feel I can fix anything, especially with the set-password case. Since I am only using the OAuth flow, I don't actually need to set or reset passwords, so I haven't been able to test those flows too much.~