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

Danielle/homepage-flickers-as-it-checks-authentication #654

Conversation

Danielle254
Copy link
Contributor

@Danielle254 Danielle254 commented Nov 7, 2024

Closes #635

Issue:
If user is logged in and goes to gridironsurvivor.com or gridironsurvivor.com/login, the login page displays briefly before the user is redirected to the leagues landing page.

Desired behavior:
A user who is already logged in should see the global spinner (pulsing logo) while authentication takes place, then is taken straight to leagues landing page. Login page should not display at all.
For a user who is not logged in, the global spinner should display while authentication is checked, then see the login page.

Solution:

  • updated the isSignedIn variable to have 3 states instead of the previous 2 - null, true, false. Null will satisfy the condition where authentication is being checked. If the user is logged in, state goes to true. If not logged in, state goes to false.
  • wrapped the page in the GlobalSpinner and added conditional rendering so that, if the user is logged in, they only see the spinner followed by the page redirect
  • updated the tests to reflect the spinner displaying while authentication is checked, then either redirecting the logged in user to the leagues landing page or loading the login page if the user is not logged in

Copy link

appwrite bot commented Nov 7, 2024

Gridiron Survivor Application 6616ea581ef9f5521c7d

Function ID Status Action
Your function deployment has failed. Please check the logs for more details and retry.

Project name: Gridiron Survivor Application
Project ID: 6616ea581ef9f5521c7d

Function ID Status Action
userAuth 6626fef885a9f630442b failed Failed View Logs

Only deployments on the production branch are activated automatically. If you'd like to activate this deployment, navigate to your deployments. Learn more about Appwrite Function deployments.

💡 Did you know?
You can use Avatars API to generate QR code for any text or URLs

Copy link

vercel bot commented Nov 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gridiron-survivor ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2024 3:51pm
gridiron-survivor-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2024 3:51pm

@Danielle254 Danielle254 marked this pull request as ready for review November 12, 2024 19:11
@Danielle254 Danielle254 changed the title fix: initial draft code to address login page appearing before redire… Danielle/homepage-flickers-as-it-checks-authentication Nov 12, 2024
login: jest.Mock;
}

let mockUseAuthContext: MockUseAuthContext = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The original const was fine since I don't think we plan on reassigning a new object to mockUseAuthContext.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CorinaMurg good point! Changed back to const.

</p>
<p className="hidden leading-7 xl:block">Jimmy Fallon</p>
<section className={`grid ${isSignedIn === null ? '' : 'xl:grid-cols-2'} xl:grid-rows-none`}>
{(isSignedIn === null || isSignedIn === true) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can make these conditional statements more cleaner.

Ex: {isSignedIn !== false ? (<GlobalSpinner />) : (<> Rest of code </>)}

Since null and true aren't false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexappleget I like the explicit nature of these calls from a clarity of code perspective.

change let to const for mockUseAuthContext object
@@ -23,7 +23,7 @@ type AuthContextType = {
getUser: () => Promise<IUser | undefined>;
login: (user: UserCredentials) => Promise<void | Error>; // eslint-disable-line no-unused-vars
logoutAccount: () => Promise<void | Error>;
isSignedIn: boolean;
isSignedIn: boolean | null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is isSignedIn null?

@@ -39,7 +39,7 @@ export const AuthContextProvider = ({
}: {
children: React.ReactNode;
}): JSX.Element => {
const [isSignedIn, setIsSignedIn] = useState<boolean>(false);
const [isSignedIn, setIsSignedIn] = useState<boolean | null>(null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the default null and not false?


render(<Login />);

expect(screen.getByTestId('global-spinner')).toBeInTheDocument();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to test that global-spinner is not in the document as well when isSignedIn is either false or true.

…n-survivor into danielle/635-bug-homepage-flickers-as-it-checks-authentication
…ication' of https://github.com/LetsGetTechnical/gridiron-survivor into danielle/635-bug-homepage-flickers-as-it-checks-authentication
Copy link
Contributor

@kepsteen kepsteen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM🚀

@Danielle254 Danielle254 merged commit 491d856 into develop Nov 19, 2024
5 checks passed
@Danielle254 Danielle254 deleted the danielle/635-bug-homepage-flickers-as-it-checks-authentication branch November 19, 2024 16:07
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.

Bug: Homepage flickers as it checks authentication
5 participants