Skip to content

Commit

Permalink
Merge pull request #1248 from visualize-admin/fix/flickering-username
Browse files Browse the repository at this point in the history
fix: Flickering username
  • Loading branch information
bprusinowski authored Nov 6, 2023
2 parents 4ee116a + 06c325b commit e65ac3c
Showing 1 changed file with 2 additions and 32 deletions.
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;
};

1 comment on commit e65ac3c

@vercel
Copy link

@vercel vercel bot commented on e65ac3c Nov 6, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

visualization-tool – ./

visualization-tool-ixt1.vercel.app
visualization-tool-alpha.vercel.app
visualization-tool-git-main-ixt1.vercel.app

Please sign in to comment.