Skip to content

Commit

Permalink
frontend: change local storage name of longin-secret to loginSecret s…
Browse files Browse the repository at this point in the history
…ince loginKey was pretty confusing.
  • Loading branch information
ffreddow committed Nov 5, 2024
1 parent 9dde545 commit 628788e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function logout(logout_all: boolean) {
credentials: "include",
});

localStorage.removeItem("loginKey");
localStorage.removeItem("loginSalt");
localStorage.removeItem("secretKey");

window.location.reload();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Login extends Component<{}, LoginState> {
}

const loginSaltBs64 = Base64.fromUint8Array(login_salt);
window.localStorage.setItem("loginKey", loginSaltBs64);
window.localStorage.setItem("loginSalt", loginSaltBs64);

const login_key = await generate_hash(this.state.password, login_salt);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function User() {

const t = i18n.t;

const loginSaltBs64 = window.localStorage.getItem("loginKey");
const loginSaltBs64 = window.localStorage.getItem("loginSalt");
const loginSalt = Base64.toUint8Array(loginSaltBs64);
const loginKey = await generate_hash(deleteUser.password, loginSalt)

Expand Down
9 changes: 7 additions & 2 deletions frontend/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,18 @@ export async function refresh_access_token() {
credentials: "include"
});

if (localStorage.getItem("loginKey")) {
localStorage.setItem("loginSalt", localStorage.getItem("loginKey"));
localStorage.removeItem("loginKey");
}

if (resp.status == 200) {
if (!localStorage.getItem("loginKey") || !localStorage.getItem("secretKey")) {
if (!localStorage.getItem("loginSalt") || !localStorage.getItem("secretKey")) {
logout(false);
}
loggedIn.value = AppState.LoggedIn;
} else {
localStorage.removeItem("loginKey");
localStorage.removeItem("loginSalt");
localStorage.removeItem("secretKey");
loggedIn.value = AppState.LoggedOut;
}
Expand Down

0 comments on commit 628788e

Please sign in to comment.