feat: pseudo-login
This commit is contained in:
@@ -8,7 +8,7 @@ import { AppProvider, useAppContext } from "./providers/AuthProvider";
|
|||||||
const HomePage: FunctionComponent = () => {
|
const HomePage: FunctionComponent = () => {
|
||||||
const { route } = useLocation();
|
const { route } = useLocation();
|
||||||
const { isLoggedIn } = useAppContext();
|
const { isLoggedIn } = useAppContext();
|
||||||
if (isLoggedIn) route("/profile/tasks", true);
|
if (isLoggedIn.value) route("/profile/tasks", true);
|
||||||
else route("/login", true);
|
else route("/login", true);
|
||||||
return <div>Redirecting...</div>;
|
return <div>Redirecting...</div>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const LoginPage: FunctionComponent = () => {
|
|||||||
color="secondary"
|
color="secondary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
isLoggedIn.value = true;
|
isLoggedIn.value = true;
|
||||||
|
localStorage.setItem("loggedIn", "true");
|
||||||
route("/profile/tasks", true);
|
route("/profile/tasks", true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const ProfileSettings: FunctionComponent = () => {
|
|||||||
color="secondary"
|
color="secondary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
isLoggedIn.value = false;
|
isLoggedIn.value = false;
|
||||||
|
localStorage.setItem("loggedIn", "false");
|
||||||
route("/login", true);
|
route("/login", true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { stringToBoolean } from "@/utils/converter";
|
||||||
import { signal, Signal } from "@preact/signals";
|
import { signal, Signal } from "@preact/signals";
|
||||||
import { createContext, JSX } from "preact";
|
import { createContext, JSX } from "preact";
|
||||||
import { useContext } from "preact/hooks";
|
import { useContext } from "preact/hooks";
|
||||||
@@ -5,14 +6,15 @@ import { useContext } from "preact/hooks";
|
|||||||
interface AppContextValue {
|
interface AppContextValue {
|
||||||
isLoggedIn: Signal<boolean>;
|
isLoggedIn: Signal<boolean>;
|
||||||
}
|
}
|
||||||
|
const ininitialValue = stringToBoolean(localStorage.getItem("loggedIn"));
|
||||||
|
|
||||||
const AppContext = createContext<AppContextValue>({
|
const AppContext = createContext<AppContextValue>({
|
||||||
isLoggedIn: signal(false),
|
isLoggedIn: signal(ininitialValue),
|
||||||
});
|
});
|
||||||
|
|
||||||
const AppProvider = ({ children }: { children: JSX.Element }) => {
|
const AppProvider = ({ children }: { children: JSX.Element }) => {
|
||||||
const value: AppContextValue = {
|
const value: AppContextValue = {
|
||||||
isLoggedIn: signal(false),
|
isLoggedIn: signal(ininitialValue),
|
||||||
};
|
};
|
||||||
|
|
||||||
return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
|
return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
|
||||||
|
|||||||
5
src/utils/converter.ts
Normal file
5
src/utils/converter.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export const stringToBoolean = (value: string | null): boolean => {
|
||||||
|
if (value === "true") return true;
|
||||||
|
if (value === "false") return false;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user