add logout mechanism

This commit is contained in:
Sepehr Safari
2023-06-03 12:05:20 +03:30
committed by fiatjaf_
parent 27bc7024bf
commit a88ae261bf
6 changed files with 7053 additions and 648 deletions

6475
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,12 @@
/** abstracted to improve testability */
export const localStorageGetItem = (key:string):string | null => localStorage.getItem(key);
export const localStorageGetItem = (key: string): string | null => localStorage.getItem(key);
/** abstracted to improve testability */
export const localStorageSetItem = (key:string, value:string):void => {
export const localStorageSetItem = (key: string, value: string): void => {
localStorage.setItem(key, value);
};
/** abstracted to improve testability */
export const localStorageClear = (): void => {
localStorage.clear();
};

8
src/Logout.ts Normal file
View File

@@ -0,0 +1,8 @@
import { localStorageClear } from './LocalStorage';
const Logout = () => {
localStorageClear();
window.location.href = '/';
};
export default Logout;

View File

@@ -1,27 +1,30 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="style.css" />
<title>Nostr Profile Manager</title>
<script async src="index.js"></script>
</head>
<body>
<div class="nav-container">
<div class="container">
<nav>
<ul>
<li><strong><a href="#" id="navhome" class="secondary">Nostr Profile Manager</a></strong></li>
</ul>
<ul id="mainnav" class="inactive">
<li><a href="#" id="navmetadata" class="secondary">Metadata</a></li>
<li><a href="#" id="navcontacts" class="secondary">Contacts</a></li>
<li><a href="#" id="navrelays" class="secondary">Relays</a></li>
</ul>
</nav>
</div>
<div class="nav-container">
<div class="container">
<nav>
<ul>
<li>
<strong><a href="#" id="navhome" class="secondary">Nostr Profile Manager</a></strong>
</li>
</ul>
<ul id="mainnav" class="inactive">
<li><a href="#" id="navmetadata" class="secondary">Metadata</a></li>
<li><a href="#" id="navcontacts" class="secondary">Contacts</a></li>
<li><a href="#" id="navrelays" class="secondary">Relays</a></li>
<li><a href="#" id="navlogout" class="secondary">Logout</a></li>
</ul>
</nav>
</div>
<div id="PM-container"></div>
</div>
<div id="PM-container"></div>
</body>
</html>

View File

@@ -5,13 +5,14 @@ import { localStorageGetItem, localStorageSetItem } from './LocalStorage';
import { LoadMetadataPage } from './LoadMetadataPage';
import LoadContactsPage from './LoadContactsPage';
import LoadRelaysPage from './LoadRelaysPage';
import Logout from './Logout';
declare global {
interface Window {
nostr?: {
getPublicKey: () => Promise<string>;
signEvent: (event:UnsignedEvent) => Promise<Event>;
}
signEvent: (event: UnsignedEvent) => Promise<Event>;
};
}
}
@@ -19,10 +20,7 @@ const loadProfile = async () => {
// load profile page (in loading mode)
LoadProfileHome();
// load profile data
await fetchMyProfileEvents(
localStorageGetItem('pubkey') as string,
LoadProfileHome,
);
await fetchMyProfileEvents(localStorageGetItem('pubkey') as string, LoadProfileHome);
// load profile page (in complete mode)
LoadProfileHome();
// turn on nav
@@ -31,6 +29,7 @@ const loadProfile = async () => {
(document.getElementById('navmetadata') as HTMLElement).onclick = LoadMetadataPage;
(document.getElementById('navcontacts') as HTMLElement).onclick = LoadContactsPage;
(document.getElementById('navrelays') as HTMLElement).onclick = LoadRelaysPage;
(document.getElementById('navlogout') as HTMLElement).onclick = Logout;
// get events from my contacts
await fetchMyContactsProfileEvents();
};
@@ -64,7 +63,7 @@ const LoadLandingPage = () => {
</div>
</div>
`;
const o:HTMLElement = document.getElementById('PM-container') as HTMLElement;
const o: HTMLElement = document.getElementById('PM-container') as HTMLElement;
o.innerHTML = aboutcontent;
const a = document.getElementById('loadextension');
if (a) {

1157
yarn.lock

File diff suppressed because it is too large Load Diff