testing new PWA auth
This commit is contained in:
parent
697cd4ce66
commit
75361788a7
@ -19,6 +19,7 @@ export default function LoginModal() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const shouldReconnect = localStorage.getItem("shouldReconnect");
|
const shouldReconnect = localStorage.getItem("shouldReconnect");
|
||||||
|
const savedNsec = localStorage.getItem("nsec");
|
||||||
|
|
||||||
const getConnected = async (shouldReconnect: string) => {
|
const getConnected = async (shouldReconnect: string) => {
|
||||||
let enabled: boolean | void = false;
|
let enabled: boolean | void = false;
|
||||||
@ -52,8 +53,9 @@ export default function LoginModal() {
|
|||||||
}
|
}
|
||||||
return enabled;
|
return enabled;
|
||||||
};
|
};
|
||||||
|
if (savedNsec) {
|
||||||
if (shouldReconnect === "true") {
|
handleLoginNsec(savedNsec);
|
||||||
|
} else if (shouldReconnect === "true") {
|
||||||
getConnected(shouldReconnect);
|
getConnected(shouldReconnect);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
@ -70,7 +72,6 @@ export default function LoginModal() {
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error("NO auth");
|
throw new Error("NO auth");
|
||||||
}
|
}
|
||||||
console.log("LOGIN", user);
|
|
||||||
await loginWithPubkey(nip19.decode(user.npub).data.toString());
|
await loginWithPubkey(nip19.decode(user.npub).data.toString());
|
||||||
localStorage.setItem("shouldReconnect", "true");
|
localStorage.setItem("shouldReconnect", "true");
|
||||||
}
|
}
|
||||||
@ -82,17 +83,17 @@ export default function LoginModal() {
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
modal?.hide();
|
modal?.hide();
|
||||||
}
|
}
|
||||||
async function handleLoginNsec() {
|
async function handleLoginNsec(nsec_?: string) {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
console.log("loging in");
|
console.log("loging in");
|
||||||
|
|
||||||
const user = await loginWithSecret(nsec);
|
const user = await loginWithSecret(nsec_ ?? nsec);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error("NO auth");
|
throw new Error("NO auth");
|
||||||
}
|
}
|
||||||
console.log("LOGIN", user);
|
console.log("LOGIN", user);
|
||||||
await loginWithPubkey(nip19.decode(user.npub).data.toString());
|
await loginWithPubkey(nip19.decode(user.npub).data.toString());
|
||||||
localStorage.setItem("shouldReconnect", "true");
|
localStorage.setItem("nsec", nsec);
|
||||||
|
|
||||||
if (typeof window.webln !== "undefined") {
|
if (typeof window.webln !== "undefined") {
|
||||||
await window.webln.enable();
|
await window.webln.enable();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user