epilande/gatsby-theme-auth0

isLoading showing slow loading

Opened this issue · 0 comments

dandv commented

I've implemented the isLoading mechanism from the minimal demo in the top nav of my site, to show "Session loading...".

It's taking 1-2 seconds on every page transition, from the index to a statically generated page (which otherwise loads nearly instantly). All of this on localhost. Is that normal?

Gatsby-auth0-slow

Here's my TopNav code:

import React, { ReactElement } from 'react';
import { Link } from 'gatsby';
import ListLink from './ListLink';
import { AuthService, useAuth } from 'gatsby-theme-auth0';
import './TopNav.css';

export default function TopNav(): ReactElement {
  const { isLoading, isLoggedIn, profile } = useAuth();
  return (
    <nav className="navbar" style={{ fontSize: '1.1em' }}>
      <ul className="nav-links">
        <ListLink to="/faq/">FAQ</ListLink>
        <ListLink to="/about/">About</ListLink>
        {isLoading ? (
          <p>Session loading...</p>
        ) : isLoggedIn ? (
          <button onClick={AuthService.logout}>Logout</button>
        ) : (
          <button onClick={AuthService.login}>Login</button>
        )}
        {profile && <p>Hello {profile.name}</p>}
      </ul>
    </nav>
  );
}