Skip to content

Commit

Permalink
feat: move relay connection back to method
Browse files Browse the repository at this point in the history
  • Loading branch information
oreHGA authored Jan 17, 2024
1 parent 7a65947 commit 7ed1df2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
8 changes: 1 addition & 7 deletions frontend/src/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getServerSession } from "next-auth";
import { signIn } from "next-auth/react";
import { getPublicKey } from "nostr-tools";

import { authService, relay } from "~/services";
import { authService } from "~/services";
import { MainLayout, Meta } from "~/components/layouts";
import { Button, Input, Logo } from "~/components/ui";
import { PRIVATE_KEY, getPrivateKey } from "~/utils/auth";
Expand Down Expand Up @@ -36,12 +36,6 @@ const LoginPage = () => {
})();
}, []);

useEffect(() => {
(async () => {
await relay.connect();
})();
}, []);

const updateKeys = (privateKey: string) => {
if (privateKey && privateKey.length === 64) {
localStorage.setItem(PRIVATE_KEY, privateKey);
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ import { nip19, nip04, relayInit } from "nostr-tools";

import { api } from "~/config";

export const relay = relayInit(process.env.NEXT_PUBLIC_FUSION_RELAY_URL!);
relay.on("connect", () => {
console.log(`connected to ${relay.url}`);
});
relay.on("error", () => {
console.log(`failed to connect to ${relay.url}`);
});

interface AuthResponse {
userNpub: string;
authToken: string;
Expand All @@ -21,6 +13,15 @@ class AuthService {
const serverPublicKey = process.env.NEXT_PUBLIC_FUSION_NOSTR_PUBLIC_KEY;

try {
export const relay = relayInit(process.env.NEXT_PUBLIC_FUSION_RELAY_URL!);
relay.on("connect", () => {
console.log(`connected to ${relay.url}`);
});
relay.on("error", () => {
console.log(`failed to connect to ${relay.url}`);
});
await relay.connect();

const loginTimestamp = dayjs().unix();
let sub = relay.sub([
{
Expand Down

0 comments on commit 7ed1df2

Please sign in to comment.