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

Quality-of-life improvements: fix UI jumping and add a loading spinner #3

Closed
wants to merge 3 commits into from

Conversation

@vercel
Copy link

vercel bot commented Oct 7, 2023

Someone is attempting to deploy a commit to a Personal Account owned by @mryechkin on Vercel.

@mryechkin first needs to authorize it.

@6bangs
Copy link
Author

6bangs commented Oct 7, 2023

I'm also going to add social providers. Do you think it would be valuable to have in this repo or not?

@mryechkin
Copy link
Owner

Please make your own fork for any changes. I don't intend on accepting any contributions to this repo, sorry.

@mryechkin mryechkin closed this Oct 7, 2023
@6bangs
Copy link
Author

6bangs commented Oct 8, 2023

Ok 👍

@stevies
Copy link

stevies commented Nov 14, 2023

Can't find any other way to contact mryechkin - but there is more going on with the content jumping and reloading than can be fixed by css changes. React is complaining about:

Warning: Cannot update a component (HotReload) while rendering a different component (Router). To locate the bad setState() call inside Router, follow the stack trace as described in https://reactjs.org/link/setstate-in-render.

I actually briefly see an on-screen message between reloads. See screenshot.

As far as I can see when I trace - everything is loading twice with page and sign-in rendering at the wrong times:

-- page got user null
-- page redicecting to /sign-in
-- page got user null
-- page redicecting to /sign-in
-- sign-in got data { session: null }
-- sign-in got data { session: null }

Can't use useEffect in the server component so not sure how to delay the redirect.

Not relevant to this defect - but no other way to contact the author. Hope you don't mind. Excellent tutorials. Thanks. But maybe a better use case / flow would be to have the home landing page unprotected, with some secured and non-secured areas. That's more representative of normal site flows. Also, it would be good to see a Magic Link example at some point.

Screenshot 2023-11-14 174537

@6bangs
Copy link
Author

6bangs commented Nov 14, 2023

Hey @stevies. Yeah, after I submitted this I found another issue that lead to reloading/flickering and possibly also the client-side error you're seeing:

if (session?.access_token !== accessToken) {

    const {
      data: { subscription: authListener },
    } = supabase.auth.onAuthStateChange((event, session) => {
      if (session?.access_token !== accessToken) {
        router.refresh();
      }
    });

IIRC: the first time onAuthStateChange is called, session?.access_token evaluates to undefined. accessToken is null, so refresh is called unnecessarily. Future calls work as expected. The fix is to use != instead of strict inequality.

@stevies
Copy link

stevies commented Nov 14, 2023

@6bangs That does remove the error message. Thanks. Excessive flickering still a problem for me, so will try using your other changes.

@mryechkin
Copy link
Owner

@stevies thanks for bringing this up and @6bangs for the suggested fix.

I fixed it a slightly different way, by removing line 18 in the root app/layout.js:

const accessToken = session?.access_token || null;

As you said @6bangs - there's no reason for accessToken to be null on initial load, so this addresses that problem. I've pushed this fix to the main branch, alongside some other currency updates.

As for your other suggestions @stevies - I know there are improvements that can be made, and lots of other examples added, but I want this repo to stay as close to my guides as possible - and I don't plan on updating them anytime soon. I mention this at the end of my last guide and in the contributing guide in this repo. There's a reason the issues are turned off as well.

Frankly, I was hoping that Supabase would stay with the Auth Helper pattern for at least a while, but they've added yet another new package called @supabase/ssr that's supposed to replace the Next.js Auth Helpers. I'm not rewriting my guide for the 4th time, so this repo will stay on Auth Helpers. At least this time it doesn't look to be that big of a migration, but it's still annoying that they go changing things once again, and so soon.

@stevies
Copy link

stevies commented Nov 15, 2023

Thanks, @mryechkin - I fully understand. Your tutorial has give me a much better understanding of the process and an excellent start point for my own app.

@6bangs
Copy link
Author

6bangs commented Nov 15, 2023

@mryechkin agreed, and ssr isn't really ready yet. I tried migrating to it without any metadata, etc, and ran into this: supabase/auth-helpers#643

Hopefully it'll reach stability soon 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants