Skip to content

Commit

Permalink
wait for finished fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
ikethecoder committed Jan 7, 2025
1 parent 8ef53ba commit 1c50c83
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/nextapp/shared/services/auth/auth-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {

const identityParam = providerPage ? 'identity=provider&' : '';

if (session.status == 'loading') {
if (session.status == 'loading' || session.isFetching) {
return <></>;
}

Expand Down
6 changes: 4 additions & 2 deletions src/nextapp/shared/services/auth/use-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AuthFailedResponse {

export interface UserSessionResult {
isLoading: boolean;
isFetching: boolean;
ok: boolean;
maintenance: boolean;
user?: UserData;
Expand Down Expand Up @@ -64,17 +65,18 @@ export const getSessionL = async (): Promise<SessionData> => {
};

export const useSession = (): UserSessionResult => {
const { data, status, error, isLoading, isStale, isIdle, isFetching, isError } = useQuery<SessionData, Error>(
const { data, status, error, isLoading, isFetching } = useQuery<SessionData, Error>(
'user',
getSessionL,
{
retry: false,
refetchOnWindowFocus: true,
}
);
console.log(JSON.stringify(data), status, error, isError, isLoading, isIdle, isStale, isFetching);

return {
isLoading,
isFetching,
ok: Boolean(data?.user),
user: data?.user,
maintenance: data?.maintenance,
Expand Down

0 comments on commit 1c50c83

Please sign in to comment.