A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: add auth view for signup, login flows
thecodrrb528a33da61a
diff --git a/apps/web/src/common/reminders.js b/apps/web/src/common/reminders.jsindex d4c36bb51..906698c40 100644--- a/apps/web/src/common/reminders.js+++ b/apps/web/src/common/reminders.js@@ -5,7 +5,7 @@ import { store as appStore } from "../stores/app-store";import * as Icon from "../components/icons";import dayjs from "dayjs";import { showRecoveryKeyDialog } from "../common/dialog-controller";-import { hashNavigate } from "../navigation";+import { hashNavigate, navigate } from "../navigation";import { isDesktop } from "../utils/platform";import saveFile from "../commands/save-file";import { PATHS } from "@notesnook/desktop/paths";@@ -47,7 +47,7 @@ export const Reminders = {login: {title: "Login to sync your notes",subtitle: "You are not logged in",- action: () => hashNavigate("/login"),+ action: () => navigate("/login"),icon: Icon.User,},email: {diff --git a/apps/web/src/components/dialogs/buydialog.js b/apps/web/src/components/dialogs/buydialog.jsindex c8005be19..e88f30573 100644--- a/apps/web/src/components/dialogs/buydialog.js+++ b/apps/web/src/components/dialogs/buydialog.js@@ -13,6 +13,7 @@ import { ReactComponent as Sync } from "../../assets/sync.svg";import { ReactComponent as Vault } from "../../assets/vault.svg";import getSymbolFromCurrency from "currency-symbol-map";import { trackEvent } from "../../utils/analytics";+import { navigate } from "../../navigation";const premiumDetails = [{@@ -315,7 +316,7 @@ function BuyDialog(props) {if (isLoggedIn) {await upgrade(user, coupon, plan);} else {-+ navigate(`/login`, { redirect: `/#/buy/${coupon}` });}props.onCancel();}}diff --git a/apps/web/src/components/field/index.js b/apps/web/src/components/field/index.jsindex 88297bc0d..bff232a0f 100644--- a/apps/web/src/components/field/index.js+++ b/apps/web/src/components/field/index.js@@ -32,6 +32,7 @@ function Field(props) {label,type,sx,+ styles = {},name,required,autoFocus,@@ -52,22 +53,33 @@ function Field(props) {const [rules, setRules] = useState(passwordValidationRules);return (- <Flex sx={sx} flexDirection="column">+ <Flex sx={{ ...sx, ...styles.container }} flexDirection="column"><LabelhtmlFor={id}sx={{fontSize: "subtitle",fontWeight: "bold",- color: "text",+ color: "icon",+ flexDirection: "column",+ ...styles.label,}}>- {label}+ {label}{" "}+ {helpText && (+ <Text+ as="span"+ sx={{+ fontSize: "subBody",+ fontWeight: "normal",+ color: "fontTertiary",+ ...styles.label,+ }}+ >+ {helpText}+ </Text>+ )}</Label>- {helpText && (- <Label htmlFor={id} sx={{ fontSize: "subBody", color: "gray" }}>- {helpText}- </Label>- )}+<Flex mt={1} sx={{ position: "relative" }}><Inputdata-test-id={props["data-test-id"]}@@ -82,6 +94,7 @@ function Field(props) {autoComplete={autoComplete}type={type || "text"}sx={{+ ...styles.input,":disabled": {bg: "bgSecondary",},diff --git a/apps/web/src/components/navigation-menu/index.js b/apps/web/src/components/navigation-menu/index.jsindex 2c85e4be4..a7f78d642 100644--- a/apps/web/src/components/navigation-menu/index.js+++ b/apps/web/src/components/navigation-menu/index.js@@ -223,7 +223,7 @@ function NavigationMenu(props) {<NavigationItemtitle="Login"icon={Icon.Login}- onClick={() => hashNavigate("/login")}+ onClick={() => navigate("/login")}/>)}{bottomRoutes.map((item) => (diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.jsindex ca5b7b32b..2b6dae211 100644--- a/apps/web/src/navigation/index.js+++ b/apps/web/src/navigation/index.js@@ -66,6 +66,12 @@ export function getQueryString() {return window.location.search;}+export function getQueryParams() {+ const params = parseQuery(getQueryString());+ if (Object.keys(params).length <= 0) return;+ return params;+}+export function getCurrentPath() {return window.location.pathname || "/";}diff --git a/apps/web/src/navigation/rootroutes.js b/apps/web/src/navigation/rootroutes.jsindex 4e57136db..ff1fd5e94 100644--- a/apps/web/src/navigation/rootroutes.js+++ b/apps/web/src/navigation/rootroutes.js@@ -1,10 +1,14 @@import React from "react";import AccountRecovery from "../views/recovery";import EmailConfirmed from "../views/emailconfirmed";+import Auth from "../views/auth";const rootroutes = {- "/account/recovery": () => <AccountRecovery />,- "/account/verified": () => <EmailConfirmed />,+ "/account/recovery": () => ({ component: <AccountRecovery /> }),+ "/account/verified": () => ({ component: <EmailConfirmed /> }),+ "/signup": () => ({ component: <Auth type="signup" /> }),+ "/login": () => ({ component: <Auth type="login" /> }),+ "/recover": () => ({ component: <Auth type="recover" /> }),};export default rootroutes;diff --git a/apps/web/src/views/auth.js b/apps/web/src/views/auth.jsnew file mode 100644index 000000000..9042c24d9--- /dev/null+++ b/apps/web/src/views/auth.js@@ -0,0 +1,389 @@+import { useEffect, useState } from "react";+import { Box, Button, Flex, Text } from "rebass";+import ThemeProvider from "../components/theme-provider";+import * as Icon from "../components/icons";+import Field from "../components/field";+import { getQueryParams, navigate, useQueryParams } from "../navigation";+import { store as userstore } from "../stores/user-store";+import { db } from "../common/db";++const features = [+ {+ title: "Welcome to Notesnook",+ description:+ "Did you know that the best note taking apps can secretly read all your notes? But Notesnook is different.",+ },+ {+ title: "100% end-to-end encrypted notes",+ description:+ "All your notes are encrypted on your device. No one except you can read your notes.",+ link: "https://docs.notesnook.com/how-is-my-data-encrypted/",+ linkText: "Learn how we encrypt your data",+ },+ {+ title: "Sync to unlimited devices",+ description:+ "Notesnook works 100% offline and you can install it on all your mobile, tablet and PC. Your notes are always with you where ever you go.",+ },+ {+ title: "Write better. Faster. Smarter.",+ description:+ "Edit your notes the way you want. You can add images, videos, tables and even use markdown.",+ },+ {+ title: "Organize to remember, not to put away",+ description:+ "With notebooks, tags and colors you can find your notes easily.",+ },+ {+ title: "Join our community",+ description:+ "We are not ghosts, chat with us and share your experience. Give suggestions, report issues and meet other people using Notesnook",+ link: "https://discord.gg/zQBK97EE22",+ linkText: "Join now",+ },+];++var interval = null;+const authTypes = {+ signup: {+ title: "Create an account",+ subtitle: {+ text: "Already have an account?",+ action: {+ text: "Log in",+ onClick: () => navigate("/login", getQueryParams()),+ },+ },+ labels: { email: "Your email", password: "Set password" },+ autoComplete: { password: "new-password" },+ primaryAction: {+ text: "Create account",+ loadingText: "Creating account...",+ },+ secondaryAction: {+ text: "I want to try the app first",+ onClick: () => navigate("/"),+ },+ agreementText: (+ <>+ By pressing "Create account" button, you agree to our{" "}+ <Text+ as="a"+ color="primary"+ target="_blank"+ rel="noreferrer"+ href="https://notesnook.com/tos"+ >+ Terms of Service+ </Text>{" "}+ &{" "}+ <Text+ as="a"+ color="primary"+ rel="noreferrer"+ href="https://notesnook.com/privacy"+ >+ Privacy Policy+ </Text>+ .+ </>+ ),+ onSubmit: async (form, onError) => {+ return await userstore+ .signup(form)+ .then(async () => navigate(form.redirect || "/"))+ .catch((e) => onError(e.message));+ },+ },+ login: {+ title: "Welcome back!",+ subtitle: {+ text: "Don't have an account?",+ action: {+ text: "Sign up!",+ onClick: () => navigate("/signup", getQueryParams()),+ },+ },+ autoComplete: { password: "current-password" },+ labels: { email: "Your email", password: "Your password" },+ primaryAction: {+ text: "Login to your account",+ loadingText: "Logging in...",+ },+ supportsPasswordRecovery: true,+ onSubmit: async (form, onError) => {+ return await userstore+ .login(form)+ .then(async () => navigate(form.redirect || "/"))+ .catch((e) => onError(e.message));+ },+ },+ recover: {+ title: "Recover your account",+ subtitle: {+ text: "Remember your password?",+ action: {+ text: "Log in",+ onClick: () => navigate("/login", getQueryParams()),+ },+ },+ helpTexts: {+ email:+ "Enter your Notesnook account email so we can send you instructions on how to recover your account.",+ },+ labels: { email: "Email address" },+ primaryAction: {+ text: "Recover account",+ loadingText: "Sending recovery email...",+ },+ onSubmit: async (form, onError, onSuccess) => {+ return await db.user+ .recoverAccount(form.email.toLowerCase())+ .then(async () =>+ onSuccess("Recovery email sent. Please check your inbox (and spam).")+ )+ .catch((e) => onError(e.message));+ },+ },+};++function Auth(props) {+ const { type } = props;+ const [{ redirect }] = useQueryParams();+ const [isSubmitting, setIsSubmitting] = useState(false);+ const [error, setError] = useState();+ const [success, setSuccess] = useState();+ const [featureIndex, setFeatureIndex] = useState(0);++ const data = authTypes[type];+ const feature = features[featureIndex];++ useEffect(() => {+ clearInterval(interval);+ interval = setInterval(() => {+ setFeatureIndex((s) => ++s % features.length);+ }, 5000);+ return () => {+ clearInterval(interval);+ };+ }, []);++ useEffect(() => {+ if (isSubmitting) {+ setError();+ setSuccess();+ }+ }, [isSubmitting]);++ return (+ <ThemeProvider>+ <Flex+ bg="background"+ height={"100%"}+ overflowY="auto"+ flexDirection={"row"}+ >+ <Box+ flexDirection="column"+ justifyContent="center"+ flex={0.35}+ bg="primary"+ p={50}+ display={["none", "none", "flex"]}+ >+ <Flex+ flexDirection="column"+ justifyContent="center"+ alignItems="start"+ >+ <Flex+ mt={4}+ alignItems="center"+ sx={{ cursor: "pointer" }}+ title="Go back to app"+ onClick={() => navigate("/")}+ >+ <Icon.ArrowLeft size={22} color="static" />+ <Text+ color="static"+ variant="title"+ fontWeight="heading"+ ml={1}+ fontSize={20}+ >+ Notesnook+ </Text>+ </Flex>++ <Flex mt={100} flexDirection="column" height={250}>+ <Text+ color="static"+ variant="heading"+ fontWeight="bold"+ fontSize="2em"+ >+ {feature.title}+ </Text>+ <Text mt={4} variant="body" fontSize={"1.1em"} color="static">+ {feature.description}+ </Text>+ {feature.link && (+ <Flex+ as="a"+ sx={{+ textDecorationLine: "underline",+ textDecorationColor: "#fff",+ }}+ href={feature.link}+ mt={4}+ alignItems="center"+ >+ <Icon.ArrowRight size={18} color="static" />+ <Text variant="title" ml={1} color="static">+ {feature.linkText}+ </Text>+ </Flex>+ )}+ </Flex>+ <Flex alignSelf="center" mt={50}>+ {features.map((_, i) => (+ <Box+ key={i}+ height={5}+ width={20}+ mr={1}+ sx={{ borderRadius: 100 }}+ bg={featureIndex === i ? "static" : "#ffffff99"}+ onClick={() => setFeatureIndex(i)}+ />+ ))}+ </Flex>+ </Flex>+ </Box>+ <Flex justifyContent="center" flex={1} flexShrink={0}>+ <Flex+ as="form"+ flexDirection="column"+ justifyContent="center"+ alignItems="stretch"+ width={["95%", "55%", "35%"]}+ onSubmit={async (e) => {+ e.preventDefault();+ setIsSubmitting(true);+ const form = new FormData(e.target);+ const obj = Object.fromEntries(form.entries());+ obj.redirect = redirect;+ await data.onSubmit(obj, setError, setSuccess);+ setIsSubmitting(false);+ }}+ >+ <Text variant="heading" textAlign="center" fontWeight="heading">+ {data.title}+ </Text>+ <Text variant="body" mt={1} textAlign="center" color="fontTertiary">+ {data.subtitle.text}{" "}+ {data.subtitle.action && (+ <Text+ sx={{ ":hover": { color: "dimPrimary" }, cursor: "pointer" }}+ as="b"+ color="primary"+ onClick={data.subtitle.action.onClick}+ >+ {data.subtitle.action.text}+ </Text>+ )}+ </Text>+ <Field+ styles={{+ container: { mt: 50 },+ }}+ id="email"+ required+ name="email"+ autoComplete="email"+ label={data.labels.email}+ helpText={data.helpTexts?.email}+ />+ {data.labels.password && (+ <Field+ styles={{+ container: { mt: 2 },+ }}+ id="password"+ required+ name="password"+ autoComplete={data.autoComplete?.password}+ label={data.labels.password}+ type="password"+ />+ )}++ {data.supportsPasswordRecovery && (+ <Button+ type="button"+ alignSelf="start"+ mt={2}+ variant="anchor"+ onClick={() => navigate("/recover", getQueryParams())}+ >+ Forgot password?+ </Button>+ )}+ <Button+ display="flex"+ type="submit"+ mt={4}+ variant="primary"+ disabled={isSubmitting}+ sx={{ borderRadius: "default" }}+ justifyContent="center"+ alignItems="center"+ >+ {isSubmitting ? (+ <>+ <Icon.Loading color="static" size={16} sx={{ mr: 1 }} />{" "}+ {data.primaryAction.loadingText}+ </>+ ) : (+ data.primaryAction.text+ )}+ </Button>+ {data.secondaryAction && (+ <Button+ type="button"+ variant="secondary"+ mt={1}+ onClick={data.secondaryAction.onClick}+ >+ {data.secondaryAction.text}+ </Button>+ )}+ {error && (+ <Flex bg="errorBg" p={1} mt={2} sx={{ borderRadius: "default" }}>+ <Icon.Error size={15} color="error" />+ <Text variant="error" ml={1}>+ {error}+ </Text>+ </Flex>+ )}+ {success && (+ <Flex bg="shade" p={1} mt={2} sx={{ borderRadius: "default" }}>+ <Icon.CheckCircle size={15} color="primary" />+ <Text variant="error" color="primary" ml={1}>+ {success}+ </Text>+ </Flex>+ )}+ {data.agreementText && (+ <Text mt={2} variant="subBody">+ {data.agreementText}+ </Text>+ )}+ </Flex>+ </Flex>+ </Flex>+ </ThemeProvider>+ );+}+export default Auth;diff --git a/apps/web/src/views/recovery.js b/apps/web/src/views/recovery.jsindex a7517c346..8e627fe05 100644--- a/apps/web/src/views/recovery.js+++ b/apps/web/src/views/recovery.js@@ -297,7 +297,7 @@ function FinalStep() {<Step heading="Account recovered!"><Buttonvariant="secondary"- onClick={() => (window.location.href = "/#/login")}+ onClick={() => (window.location.href = "/login")}>Login using new password</Button>diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.jsindex ebf838e2e..89f224414 100644--- a/apps/web/src/views/settings.js+++ b/apps/web/src/views/settings.js@@ -21,7 +21,7 @@ import ScrollContainer from "../components/scroll-container";import { showLoadingDialog } from "../common/dialog-controller";import { showToast } from "../utils/toast";import { showPasswordDialog } from "../common/dialog-controller";-import { hashNavigate } from "../navigation";+import { hashNavigate, navigate } from "../navigation";import useVersion from "../utils/useVersion";import { CHECK_IDS } from "notes-core/common";import { openPaddleDialog } from "../common/checkout";@@ -166,7 +166,7 @@ function Settings(props) {p={1}sx={{ borderRadius: "default", cursor: "pointer" }}onClick={async () => {-+ navigate("/login", { redirect: "/settings" });}}><Flex