Describe the bug
I'm currently developing a sample app with Frontendegg's authentication, utilizing the React integration guide. However, I am using Vite instead of Create React App (CRA) for this project.
The authentication process works as expected, but I encountered an issue when trying to display a loading component during this process. It seems that the isLoading state from useAuth() consistently returns false.
I discovered the isLoading property by inspecting the return type of useAuth(). However, I found no mention of it in the existing documentation.
This leads me to two questions:
- Is there an API reference for the React SDK that might explain this
isLoading property?
- How can I correctly obtain the loading state during the authentication process?
To Reproduce
Steps to reproduce the behavior:
- Go to integration guide for React
- Follow the instruction and build the app with Vite
- Change
const { user, isAuthenticated } = useAuth() with const { user, isAuthenticated, isLoading } = useAuth()
- Return loading component when
isLoading is true e.g. if (isLoading) return <div>Loading...</div>
- You can see it's not rendered.
Expected behavior
I expect the 'isLoading' state to consistently return 'true' during the entire authentication process.
Screenshots
n/a
import { useEffect } from "react";
import "./App.css";
import { ContextHolder, useAuth, useLoginWithRedirect } from "@frontegg/react";
function App() {
const { user, isAuthenticated, isLoading } = useAuth();
const loginWithRedirect = useLoginWithRedirect();
useEffect(() => {
if (!isAuthenticated) {
loginWithRedirect();
}
}, [isAuthenticated, loginWithRedirect]);
const logout = () => {
const baseUrl = ContextHolder.getContext().baseUrl;
window.location.href = `${baseUrl}/oauth/logout?post_logout_redirect_uri=${window.location}`;
};
// HERE: This div should be rendered but the 'Click me to login' button will be rendered
if (isLoading) return <div>Loading...</div>;
return (
<div className="App">
{isAuthenticated ? (
<div>
<div>
<img src={user?.profilePictureUrl || undefined} alt={user?.name} />
</div>
<div>
<span>Logged in as: {user?.name}</span>
</div>
<div>
<button onClick={() => alert(user?.accessToken)}>
What is my access token?
</button>
</div>
<button onClick={() => logout()}>Click to logout</button>
</div>
) : (
<div>
<button onClick={() => loginWithRedirect()}>Click me to login</button>
</div>
)}
</div>
);
}
export default App;
Additional context
I am using
Vite: 4.4.5
React: 18.2.0
@frontegg/react: 5.0.46
Feel free to ask me anything if you guys need more information. Thanks.
Describe the bug
I'm currently developing a sample app with Frontendegg's authentication, utilizing the React integration guide. However, I am using Vite instead of Create React App (CRA) for this project.
The authentication process works as expected, but I encountered an issue when trying to display a loading component during this process. It seems that the
isLoadingstate fromuseAuth()consistently returnsfalse.I discovered the
isLoadingproperty by inspecting the return type ofuseAuth(). However, I found no mention of it in the existing documentation.This leads me to two questions:
isLoadingproperty?To Reproduce
Steps to reproduce the behavior:
const { user, isAuthenticated } = useAuth()withconst { user, isAuthenticated, isLoading } = useAuth()isLoadingistruee.g.if (isLoading) return <div>Loading...</div>Expected behavior
I expect the 'isLoading' state to consistently return 'true' during the entire authentication process.
Screenshots
n/a
Additional context
I am using
Vite: 4.4.5
React: 18.2.0
@frontegg/react: 5.0.46
Feel free to ask me anything if you guys need more information. Thanks.