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 */ /** 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 */ /** abstracted to improve testability */
export const localStorageSetItem = (key:string, value:string):void => { export const localStorageSetItem = (key: string, value: string): void => {
localStorage.setItem(key, value); 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"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css" />
<title>Nostr Profile Manager</title> <title>Nostr Profile Manager</title>
<script async src="index.js"></script> <script async src="index.js"></script>
</head> </head>
<body> <body>
<div class="nav-container"> <div class="nav-container">
<div class="container"> <div class="container">
<nav> <nav>
<ul> <ul>
<li><strong><a href="#" id="navhome" class="secondary">Nostr Profile Manager</a></strong></li> <li>
</ul> <strong><a href="#" id="navhome" class="secondary">Nostr Profile Manager</a></strong>
<ul id="mainnav" class="inactive"> </li>
<li><a href="#" id="navmetadata" class="secondary">Metadata</a></li> </ul>
<li><a href="#" id="navcontacts" class="secondary">Contacts</a></li> <ul id="mainnav" class="inactive">
<li><a href="#" id="navrelays" class="secondary">Relays</a></li> <li><a href="#" id="navmetadata" class="secondary">Metadata</a></li>
</ul> <li><a href="#" id="navcontacts" class="secondary">Contacts</a></li>
</nav> <li><a href="#" id="navrelays" class="secondary">Relays</a></li>
</div> <li><a href="#" id="navlogout" class="secondary">Logout</a></li>
</ul>
</nav>
</div> </div>
<div id="PM-container"></div> </div>
<div id="PM-container"></div>
</body> </body>
</html> </html>

View File

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

1157
yarn.lock

File diff suppressed because it is too large Load Diff