Skip to content

Commit

Permalink
Auto-prompt login (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
n3ps authored Dec 20, 2024
1 parent 096866c commit c626b95
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect } from 'react';
import { useHistory } from '@docusaurus/router';

export function RedirectToHome() {
export function RedirectToLogin() {
const history = useHistory();

useEffect(() => {
history.replace('/');
history.replace('/login');
}, [history]);

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Dashboard/SignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function DesktopUserMenu({ user, logout }) {
},
{
label: 'Sign Out',
href: '/',
href: '#',
onClick: logout,
},
]}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ConsumptionStats } from '@site/src/modules/Dashboard/ConsumptionStats';
import { Breadcrumbs } from '@site/src/modules/Dashboard/Breadcrumbs';
import { QuickLinks } from '@site/src/components/QuickLinks';
import { Card } from '../components/Card';
import { RedirectToHome } from '@site/src/components/RedirectToHome';
import { RedirectToLogin } from '@site/src/components/RedirectToLogin';

function Dashboard() {
return (
Expand All @@ -19,7 +19,7 @@ function Dashboard() {
<Breadcrumbs title="Dashboard" />

<SignedOut>
<RedirectToHome />
<RedirectToLogin />
</SignedOut>

<SignedIn>
Expand Down
27 changes: 27 additions & 0 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useEffect } from 'react';
import { useHistory } from '@docusaurus/router';
import { useModalStatus } from '@privy-io/react-auth';
import { useSignIn } from '@site/src/helpers/useSignIn';

function LoginPage() {
const history = useHistory();
const { isOpen } = useModalStatus();

const redirectToDashboard = () => {
history.push('/dashboard');
};

const { authenticated, ready, login } = useSignIn({
onComplete: redirectToDashboard,
});

useEffect(() => {
if (!ready || authenticated || isOpen) return;

login();
}, [ready, authenticated, isOpen, login]);

return null;
}

export default LoginPage;

0 comments on commit c626b95

Please sign in to comment.