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

fix: Flickering username #1248

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 2 additions & 32 deletions app/login/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Theme } from "@mui/material";
import { makeStyles } from "@mui/styles";
import { getProviders, useSession } from "next-auth/react";
import React from "react";
import { useSession } from "next-auth/react";

import { HEADER_HEIGHT } from "@/components/header";

Expand All @@ -24,39 +23,10 @@ export const useRootStyles = makeStyles<Theme>((theme) => ({

export const useUser = () => {
const { data: session, status: sessionStatus } = useSession();
const { data: providers, status: providersStatus } = useProviders();

if (sessionStatus === "loading" || providersStatus === "loading") {
return null;
}

if (!providers || !Object.keys(providers).length) {
return null;
}

if (!session) {
if (sessionStatus === "loading" || !session) {
return null;
}

return session.user;
};

type Providers = Awaited<ReturnType<typeof getProviders>>;

const useProviders = () => {
const [state, setState] = React.useState({
status: "loading",
data: undefined as Providers | undefined,
});

React.useEffect(() => {
const run = async () => {
const providers = await getProviders();
setState({ status: "loaded", data: providers });
};

run();
}, []);

return state;
};
Loading