Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: properly handle first startup

thecodrr82d6d1711214
diff --git a/apps/web/src/index.js b/apps/web/src/index.js
index 7829a170f..3032dc9c9 100644
--- a/apps/web/src/index.js
+++ b/apps/web/src/index.js
@@ -35,10 +35,6 @@ function getRoute() {
return ROUTES[path];
}
-function shouldSkipInitiation() {
- return localStorage.getItem("skipInitiation") || false;
-}
-
const route = getRoute();
route.component().then(({ default: Component }) => {
render(
@@ -55,3 +51,7 @@ route.component().then(({ default: Component }) => {
// Learn more about service workers: https://bit.ly/CRA-PWA
if (process.env.REACT_APP_PLATFORM !== "desktop") serviceWorker.register();
else serviceWorker.unregister();
+
+function shouldSkipInitiation() {
+ return localStorage.getItem("skipInitiation") || false;
+}
diff --git a/apps/web/src/views/auth.js b/apps/web/src/views/auth.js
index 95cbc1083..37b3530b4 100644
--- a/apps/web/src/views/auth.js
+++ b/apps/web/src/views/auth.js
@@ -98,7 +98,9 @@ const authTypes = {
}
return await userstore
.signup(form)
- .then(async () => hardNavigate(form.redirect || "/"))
+ .then(async () => {
+ redirectToURL(form.redirect || "/");
+ })
.catch((e) => onError(e.message));
},
},
@@ -122,7 +124,9 @@ const authTypes = {
onSubmit: async (form, onError) => {
return await userstore
.login(form)
- .then(async () => hardNavigate(form.redirect || "/"))
+ .then(async () => {
+ redirectToURL(form.redirect || "/");
+ })
.catch((e) => onError(e.message));
},
},
@@ -194,6 +198,14 @@ function Auth(props) {
}
}, [type]);
+ useEffect(() => {
+ if (!isAppLoaded) return;
+ (async () => {
+ const user = await db.user.getUser();
+ if (!!user) redirectToURL("/");
+ })();
+ }, [isAppLoaded]);
+
return (
<ThemeProvider>
<Flex
@@ -209,8 +221,7 @@ function Auth(props) {
sx={{ position: "absolute", top: 3, right: 30, cursor: "pointer" }}
title="Go to app"
onClick={() => {
- Config.set("skipInitiation", true);
- hardNavigate("/");
+ redirectToURL("/");
}}
>
<ArrowRight size={16} />
@@ -458,3 +469,8 @@ function Auth(props) {
);
}
export default Auth;
+
+function redirectToURL(url) {
+ Config.set("skipInitiation", true);
+ hardNavigate(url);
+}