supabase-community / auth-ui

Pre-built Auth UI for React
https://supabase.com/docs/guides/auth/auth-helpers/auth-ui
MIT License
487 stars 121 forks source link

Support for Deno #110

Open iuioiua opened 1 year ago

iuioiua commented 1 year ago

Bug report

Describe the bug

Auth component returns nothing in Deno. I'm unsure whether this is an issue with Deno, this package, or ESM.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to https://tiny-todos.deno.dev/x. You'll see an empty web page, even though it uses the following code. This is essentially the same as the first snippet from the documentation:
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.7.0";
import { Auth } from "https://esm.sh/@supabase/auth-ui-react@0.2.6?alias=react:preact/compat&deps=preact@10.12.0";

const supabaseClient = createClient(
  Deno.env.get("SUPABASE_URL")!,
  Deno.env.get("SUPABASE_ANON_KEY")!,
);

export default function Component() {
  return <Auth supabaseClient={supabaseClient} />;
}

Expected behavior

The Auth UI should be rendered as seen in the thumbnail of the video in the documentation.

Screenshots

image

System information

Additional context

I have not yet seen any examples of the Auth UI package being used in Deno, so I wonder whether this is even possible with the current code base and Deno runtime. Am I doing something wrong?

thorwebdev commented 1 year ago

@iuioiua the Auth component needs to be client-side rendered as it's making a bunch of Ajax requests, so I think we need to put it into and island component.

I tried putting it in an island, but then I'm getting this

An error occured during route handling or page rendering.

TypeError: Cannot read properties of undefined (reading '__H')
    at a (https://esm.sh/stable/preact@10.12.0/deno/hooks.js:2:189)
    at k (https://esm.sh/stable/preact@10.12.0/deno/hooks.js:2:323)
    at P (https://esm.sh/stable/preact@10.12.0/deno/hooks.js:2:292)
    at Object.ee (https://esm.sh/v106/@supabase/auth-ui-react@0.2.6/X-YS9yZWFjdDpwcmVhY3QvY29tcGF0CmQvcHJlYWN0QDEwLjEyLjA/deno/auth-ui-react.js:2:41388)
    at https://esm.sh/v99/preact-render-to-string@5.2.4/X-ZS8q/deno/preact-render-to-string.js:12:1626
    at E (https://esm.sh/v99/preact-render-to-string@5.2.4/X-ZS8q/deno/preact-render-to-string.js:12:1653)
    at E (https://esm.sh/v99/preact-render-to-string@5.2.4/X-ZS8q/deno/preact-render-to-string.js:12:918)
    at E (https://esm.sh/v99/preact-render-to-string@5.2.4/X-ZS8q/deno/preact-render-to-string.js:12:1729)
    at E (https://esm.sh/v99/preact-render-to-string@5.2.4/X-ZS8q/deno/preact-render-to-string.js:12:2689)
    at E (https://esm.sh/v99/preact-render-to-string@5.2.4/X-ZS8q/deno/preact-render-to-string.js:12:2578)

Any ideas how to resolve that? I think it's some react <> preact (in)compatability issues.

iuioiua commented 1 year ago

I've managed to get further. Try:

  1. Using ?target=es2022 on the @supabase/auth-helpers-shared import.
  2. Getting your SupaAuthUi island accept parameters supabaseUrl and supabaseKey, then define those values in the route.
  3. Only import client-side code in the island. For example, doing import { createBrowserClient } from "../components/supabase.ts"; in islands/SupaAuthUi.tsx also imports other server-side code.

I'll try get my code uploaded soon.

iuioiua commented 1 year ago

@thorwebdev, I'll create a simplified dummy repo to reproduce this issue.

iuioiua commented 1 year ago

@thorwebdev, I've created a minimal reproduction of this issue so we can play around with this issue. Hopefully, we'll get the Supabase Auth UI working with Fresh. Check it out here: https://github.com/iuioiua/fresh-supabase-auth-ui

thorwebdev commented 1 year ago

@iuioiua when running your repo https://github.com/iuioiua/fresh-supabase-auth-ui I don't get anything rendered to the screen, but I'm afraid I have no idea why that is.

Probably would need someone with deep Fresh <> React <> Preact experiece to dig into this.

I think for the time being you'd be best off using the Auth approach employed here: https://github.com/thorwebdev/everydaylytics

It uses Fresh's way of submitting forms (whereas the Auth UI uses Ajax requests), as well as cookies to store sessions (rather than Auth UI using localStorage), so I think for Fresh, the current Auth UI approach isn't the best fit.

You can find more details on the Auth approach, including Oauth here: https://github.com/thorwebdev/everydaylytics#auth-approach

iuioiua commented 1 year ago

I see. Thanks for looking into it, either way, @thorwebdev! Very much appreciated.

thorwebdev commented 1 year ago

I'll keep this open to track Deno support for the future 👍