Skip to content

Commit

Permalink
feat: attempt login at home
Browse files Browse the repository at this point in the history
  • Loading branch information
esaminu committed Sep 28, 2023
1 parent 734b135 commit cdffb2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function App() {
<RemoveTrailingSlash />
<Routes>
<Route path="/">
<Route index element={<AuthIndicator controller={window.fastAuthController} />} />
<Route index element={<AuthIndicator />} />
<Route path="login" element={<Login />} />
<Route path="create-account" element={<CreateAccount />} />
<Route path="add-device" element={<AddDevice />} />
Expand Down
23 changes: 11 additions & 12 deletions src/components/AuthIndicator/AuthIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import * as React from 'react';
import { useEffect, useState } from 'react';
import React, { useEffect } from 'react';
import { useNavigate } from 'react-router';

import AuthIndicatorButton from './AuthIndicatorButton';
import { useAuthState } from '../../lib/useAuthState';

function AuthIndicator({ controller }) {
const [isSignedIn, setIsSignedIn] = useState<boolean>(false);
function AuthIndicator() {
const { authenticated, controllerState } = useAuthState();
const navigate = useNavigate();

useEffect(() => {
async function fetchSignedInStatus() {
const currentlySignedIn = await controller.isSignedIn();
setTimeout(() => setIsSignedIn(currentlySignedIn), 2000);
if (controllerState !== 'loading' && authenticated === false) {
navigate('/login');
}

fetchSignedInStatus();
}, [controller]);
}, [authenticated, controllerState]);

return (
<AuthIndicatorButton $buttonType="secondary" $isSignedIn={isSignedIn}>
{isSignedIn ? <p>signed in</p>
<AuthIndicatorButton $buttonType="secondary" $isSignedIn={authenticated && controllerState !== 'loading'}>
{authenticated ? <p>signed in</p>
: <p>not signed in</p>}
</AuthIndicatorButton>
);
Expand Down

0 comments on commit cdffb2c

Please sign in to comment.