-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95cc9e6
commit 2cd2f92
Showing
11 changed files
with
91 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
import { useEffect } from "react"; | ||
import { View } from "react-native"; | ||
import { useRouter } from "expo-router"; | ||
import { useSession } from "@/lib/session"; | ||
import { useIsLoggedIn } from "@/lib/session"; | ||
import { Redirect } from "expo-router"; | ||
import FullPageSpinner from "@/components/ui/FullPageSpinner"; | ||
|
||
export default function App() { | ||
const router = useRouter(); | ||
const { isLoggedIn } = useSession(); | ||
useEffect(() => { | ||
const isLoggedIn = useIsLoggedIn(); | ||
|
||
if (isLoggedIn === undefined) { | ||
// Wait until it's loaded | ||
return <FullPageSpinner />; | ||
} else if (isLoggedIn) { | ||
router.replace("dashboard"); | ||
return <Redirect href="dashboard" /> | ||
} else { | ||
router.replace("signin"); | ||
return <Redirect href="signin" /> | ||
} | ||
}, [isLoggedIn]); | ||
return <View />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import { useCallback, useMemo } from "react"; | ||
import { useCallback } from "react"; | ||
|
||
import useAppSettings from "./settings"; | ||
|
||
export function useSession() { | ||
const { settings, isLoading, setSettings } = useAppSettings(); | ||
const isLoggedIn = useMemo(() => { | ||
return isLoading ? undefined : !!settings.apiKey; | ||
}, [isLoading, settings]); | ||
const { settings, setSettings } = useAppSettings(); | ||
|
||
const logout = useCallback(() => { | ||
setSettings({ ...settings, apiKey: undefined }); | ||
}, [settings, setSettings]); | ||
|
||
return { | ||
isLoggedIn, | ||
isLoading, | ||
logout, | ||
}; | ||
} | ||
|
||
export function useIsLoggedIn() { | ||
const { settings, isLoading } = useAppSettings(); | ||
|
||
return isLoading ? undefined : !!settings.apiKey; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.