Skip to content

Commit

Permalink
Force login on app update
Browse files Browse the repository at this point in the history
  • Loading branch information
audrey-yang committed Dec 12, 2024
1 parent 4877406 commit f5ce27f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taskflow2",
"version": "0.1.4",
"version": "0.1.5",
"description": "a little task manager",
"main": ".vite/build/main/index.js",
"author": "@audrey-yang",
Expand Down
2 changes: 1 addition & 1 deletion src/main/backend/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const updateTaskField = async (id: string, field: Partial<Task>) => {

export const api = {
initDb: async (user: string) => {
db = new PouchDB(path.join(app.getPath("sessionData"), "leveldb"));
db = new PouchDB(path.join(app.getPath("sessionData"), `leveldb_${user}`));
const remoteDb = new PouchDB(`${import.meta.env.VITE_CLOUDANT_URL}_${user}`, {
auth: {
username: `${import.meta.env.VITE_CLOUDANT_USERNAME}`,
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ const darkTheme = createTheme({
});

const App: () => JSX.Element = () => {
const [isLoggedIn, setIsLoggedIn] = useState(window.localStorage.getItem("loggedIn") === "y");
const [isLoggedIn, setIsLoggedIn] = useState(
window.localStorage.getItem("loggedIn") === "y" &&
window.localStorage.getItem("username") != null &&
window.localStorage.getItem("version") === "0.1.5",
);

// Lift state out of Header for refresh
const [numUnstartedTasks, setNumUnstartedTasks] = useState(0);
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ const Login = ({ setIsLoggedIn }: { setIsLoggedIn: (isLoggedIn: boolean) => void

const submitPassword = async () => {
if (await window.api.checkPassword(password)) {
window.localStorage.setItem("loggedIn", "y");
window.localStorage.setItem("username", password);
if (window.api.checkPassword(password)) {
window.localStorage.setItem("version", "0.1.5");
window.localStorage.setItem("loggedIn", "y");
window.localStorage.setItem("username", password);
setIsLoggedIn(true);
} else {
setHasError(true);
}
setIsLoggedIn(true);
} else {
setHasError(true);
Expand Down

0 comments on commit f5ce27f

Please sign in to comment.