Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SIWE domain issue #1564

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/components/SignInDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import { signIn } from "@/actions/auth";
import { signInDialogOpenAtom } from "@/config/atoms";
import { env } from "@/lib/env";
import { SignIn, User, Wallet } from "@phosphor-icons/react/dist/ssr";
import { SignIn, User, Wallet, XCircle } from "@phosphor-icons/react/dist/ssr";
import { DialogDescription } from "@radix-ui/react-dialog";
import { useMutation } from "@tanstack/react-query";
import { useAtom, useSetAtom } from "jotai";
import { shortenHex } from "lib/shortenHex";
import { toast } from "sonner";
import { createSiweMessage } from "viem/siwe";
import { useAccount, useConnect, useSignMessage } from "wagmi";
import { z } from "zod";
Expand Down Expand Up @@ -89,19 +90,13 @@
const { nonce } = await fetch(`${env.NEXT_PUBLIC_API}/auth/siwe/nonce`)
.then((res) => res.json())
.then((data) => z.object({ nonce: z.string() }).parse(data));
const urlHostname = [
new URL(env.NEXT_PUBLIC_URL).hostname,
window.location.port,
]
.filter(Boolean)
.join(":");

const message = createSiweMessage({
address: address!,

Check warning on line 95 in src/components/SignInDialog.tsx

View workflow job for this annotation

GitHub Actions / quality-assurance

lint/style/noNonNullAssertion

Forbidden non-null assertion.
chainId: 1,
domain: urlHostname,
domain: new URL(env.NEXT_PUBLIC_SIWE_URL).hostname,
nonce,
uri: urlHostname,
uri: env.NEXT_PUBLIC_SIWE_URL,
version: "1",
});

Expand All @@ -110,6 +105,13 @@
return signIn({ message, signature });
},
onSuccess: () => setSignInDialogOpen(false),
onError: (error) => {
toast("Sign in error", {
description: error.message,
icon: <XCircle weight="fill" className="text-icon-error" />,
});
console.error(error);
},
});

return (
Expand All @@ -120,7 +122,7 @@
className="justify-start"
disabled
>
{shortenHex(address!)}

Check warning on line 125 in src/components/SignInDialog.tsx

View workflow job for this annotation

GitHub Actions / quality-assurance

lint/style/noNonNullAssertion

Forbidden non-null assertion.
</Button>
<Button
leftIcon={<SignIn weight="bold" />}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export const env = createEnv({
},
client: {
NEXT_PUBLIC_API: z.string(),
NEXT_PUBLIC_URL: z.string(),
NEXT_PUBLIC_SIWE_URL: z.string(),
NEXT_PUBLIC_PINATA_GATEWAY_URL: z.string(),
},
runtimeEnv: {
NEXT_PUBLIC_API: process.env.NEXT_PUBLIC_API_V3,
NEXT_PUBLIC_URL:
NEXT_PUBLIC_SIWE_URL:
process.env.NODE_ENV === "production"
? process.env.NEXT_PUBLIC_VERCEL_URL
: "http://localhost",
? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
: "http://localhost:3000",
PINATA_ADMIN_JWT: process.env.PINATA_ADMIN_JWT,
NEXT_PUBLIC_PINATA_GATEWAY_URL: process.env.NEXT_PUBLIC_PINATA_GATEWAY_URL,
},
Expand Down
Loading