Open5

Next.js(T3 app),NextAuth, wagmi, siweいろいろ

Hide(ひで)Hide(ひで)

appをcreateしたときの.env

# Note that not all variables here might be in use for your selected configuration

# Prisma
DATABASE_URL=file:./db.sqlite

# Next Auth
NEXTAUTH_SECRET=
NEXTAUTH_URL=http://localhost:3000

# Next Auth Discord Provider
DISCORD_CLIENT_ID=
DISCORD_CLIENT_SECRET=
Hide(ひで)Hide(ひで)

NextAuth

https://next-auth.js.org/

providers

MetaMaskの場合は

CredentialsProvider({
      name: "Ethereum",
      credentials: {
        message: {
          label: "Message",
          type: "text",
          placeholder: "0x0",
        },
        signature: {
          label: "Signature",
          type: "text",
          placeholder: "0x0",
        },
      },
      async authorize(credentials) {}

https://docs.login.xyz/integrations/nextauth.js

  • credentials
    • http://localhost:3000/api/auth/signin
    • デフォルトのログイン画面がある。
    • ここにフォームとして表示される
    • ここで定義したkey(message, signature)はauthorizeでcredentials?.message, credentials?.signatureというふうに取得できる
    • ただ、このログイン画面は不要(入力でmetamaskログインすることはないので)

getCsrfToken

Hide(ひで)Hide(ひで)

wagmi

https://wagmi.sh/

next-auth × wagmiの記事調べると
WagmiProvider 使ってる記事がよく出てくるが、その情報は古くてwagmi0.4系でdepracatedになっている。
https://wagmi.sh/docs/migration-guide#duplicate-named-exports-were-removed
WagmiConfigを使うように。