Skip to content

Commit

Permalink
chore: fix merge conflicts, update lock file and ignore siwe types
Browse files Browse the repository at this point in the history
  • Loading branch information
magiziz committed May 22, 2024
2 parents 7e1092f + d26f7c4 commit b28c8dc
Show file tree
Hide file tree
Showing 36 changed files with 1,810 additions and 2,024 deletions.
14 changes: 4 additions & 10 deletions examples/with-create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.2",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.3",
"@types/react": "^18.3.0",
"react-dom": "^18.3.0",
Expand All @@ -22,18 +22,12 @@
"buffer": "npm:buffer@6.0.3"
},
"scripts": {
"dev": "react-scripts start",
"start": "react-scripts start",
"build": "react-scripts build",
"dev": "GENERATE_SOURCEMAP=false react-scripts start",
"start": "GENERATE_SOURCEMAP=false react-scripts start",
"build": "GENERATE_SOURCEMAP=false react-scripts build",
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!@rainbow-me)/\"",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
Expand Down
7 changes: 0 additions & 7 deletions examples/with-create-react-app/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import '@rainbow-me/rainbowkit/styles.css';
import './polyfills';
import './index.css';
import React from 'react';
import ReactDOM from 'react-dom/client';
import reportWebVitals from './reportWebVitals';
import { getDefaultConfig, RainbowKitProvider } from '@rainbow-me/rainbowkit';
import { WagmiProvider } from 'wagmi';
import {
Expand Down Expand Up @@ -48,8 +46,3 @@ root.render(
</WagmiProvider>
</React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
7 changes: 0 additions & 7 deletions examples/with-create-react-app/src/polyfills.ts

This file was deleted.

15 changes: 0 additions & 15 deletions examples/with-create-react-app/src/reportWebVitals.ts

This file was deleted.

3 changes: 0 additions & 3 deletions examples/with-next-app-i18n/.eslintrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions examples/with-next-app-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"start": "next start"
},
"dependencies": {
"@rainbow-me/rainbowkit": "workspace:*",
Expand All @@ -21,8 +20,6 @@
"devDependencies": {
"@types/node": "^18.19.3",
"@types/react": "^18.3.0",
"eslint": "^8.15.0",
"eslint-config-next": "^14.2.3",
"next": "^14.2.3",
"typescript": "5.4.2"
},
Expand Down
3 changes: 0 additions & 3 deletions examples/with-next-app/.eslintrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions examples/with-next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"start": "next start"
},
"dependencies": {
"@rainbow-me/rainbowkit": "workspace:*",
Expand All @@ -20,8 +19,6 @@
"devDependencies": {
"@types/node": "^18.19.3",
"@types/react": "^18.3.0",
"eslint": "^8.15.0",
"eslint-config-next": "^14.2.3",
"next": "^14.2.3",
"typescript": "5.4.2"
},
Expand Down
3 changes: 0 additions & 3 deletions examples/with-next-custom-button/.eslintrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions examples/with-next-custom-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"start": "next start"
},
"dependencies": {
"@rainbow-me/rainbowkit": "workspace:*",
Expand All @@ -20,8 +19,6 @@
"devDependencies": {
"@types/node": "^18.19.3",
"@types/react": "^18.3.0",
"eslint": "^8.15.0",
"eslint-config-next": "^14.2.3",
"typescript": "5.4.2"
}
}
3 changes: 0 additions & 3 deletions examples/with-next-mint-nft/.eslintrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions examples/with-next-mint-nft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"start": "next start"
},
"dependencies": {
"@rainbow-me/rainbowkit": "workspace:*",
Expand All @@ -21,8 +20,6 @@
"devDependencies": {
"@types/node": "^18.19.3",
"@types/react": "^18.3.0",
"eslint": "^8.15.0",
"eslint-config-next": "^14.2.3",
"typescript": "5.4.2"
}
}
3 changes: 0 additions & 3 deletions examples/with-next-rainbow-button/.eslintrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions examples/with-next-rainbow-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"start": "next start"
},
"dependencies": {
"@rainbow-me/rainbow-button": "workspace:*",
Expand All @@ -20,8 +19,6 @@
"devDependencies": {
"@types/node": "^18.19.3",
"@types/react": "^18.3.0",
"eslint": "^8.15.0",
"eslint-config-next": "^14.2.3",
"typescript": "5.4.2"
}
}
3 changes: 0 additions & 3 deletions examples/with-next-siwe-iron-session/.eslintrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions examples/with-next-siwe-iron-session/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"start": "next start"
},
"dependencies": {
"@rainbow-me/rainbowkit": "workspace:*",
Expand All @@ -21,8 +20,6 @@
"devDependencies": {
"@types/node": "^18.19.3",
"@types/react": "^18.3.0",
"eslint": "^8.15.0",
"eslint-config-next": "^14.2.3",
"typescript": "5.4.2"
}
}
16 changes: 9 additions & 7 deletions examples/with-next-siwe-iron-session/pages/api/verify.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { withIronSessionApiRoute } from 'iron-session/next';
import { NextApiRequest, NextApiResponse } from 'next';
import { ironOptions } from './../../lib/iron';
import { createSiweMessage } from 'viem/siwe';
import { withIronSessionApiRoute } from "iron-session/next";
import { NextApiRequest, NextApiResponse } from "next";
import { ironOptions } from "./../../lib/iron";
import { createSiweMessage } from "viem/siwe";

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const { method } = req;
switch (method) {
case 'POST':
case "POST":
try {
const { message, signature } = req.body;
const siweMessage = createSiweMessage(message);
// TODO: remove @ts-ignore
// @ts-ignore
const { success, error, data } = await siweMessage.verify({
signature,
});

if (!success) throw error;

if (data.nonce !== req.session.nonce)
return res.status(422).json({ message: 'Invalid nonce.' });
return res.status(422).json({ message: "Invalid nonce." });

req.session.siwe = data;
await req.session.save();
Expand All @@ -27,7 +29,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
}
break;
default:
res.setHeader('Allow', ['POST']);
res.setHeader("Allow", ["POST"]);
res.status(405).end(`Method ${method} Not Allowed`);
}
};
Expand Down
3 changes: 0 additions & 3 deletions examples/with-next-siwe-next-auth/.eslintrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions examples/with-next-siwe-next-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"start": "next start"
},
"dependencies": {
"@rainbow-me/rainbowkit": "workspace:*",
Expand All @@ -22,8 +21,6 @@
"devDependencies": {
"@types/node": "^18.19.3",
"@types/react": "^18.3.0",
"eslint": "^8.15.0",
"eslint-config-next": "^14.2.3",
"typescript": "5.4.2"
}
}
46 changes: 27 additions & 19 deletions examples/with-next-siwe-next-auth/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// with added process.env.VERCEL_URL detection to support preview deployments
// and with auth option logic extracted into a 'getAuthOptions' function so it
// can be used to get the session server-side with 'getServerSession'
import { IncomingMessage } from 'http';
import { NextApiRequest, NextApiResponse } from 'next';
import NextAuth, { NextAuthOptions } from 'next-auth';
import CredentialsProvider from 'next-auth/providers/credentials';
import { getCsrfToken } from 'next-auth/react';
import { createSiweMessage } from 'viem/siwe';
import { IncomingMessage } from "http";
import { NextApiRequest, NextApiResponse } from "next";
import NextAuth, { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import { getCsrfToken } from "next-auth/react";
import { createSiweMessage } from "viem/siwe";

export function getAuthOptions(req: IncomingMessage): NextAuthOptions {
const providers = [
CredentialsProvider({
async authorize(credentials) {
try {
const siwe = createSiweMessage(
JSON.parse(credentials?.message || '{}')
JSON.parse(credentials?.message || "{}")
);

const nextAuthUrl =
Expand All @@ -28,19 +28,27 @@ export function getAuthOptions(req: IncomingMessage): NextAuthOptions {
}

const nextAuthHost = new URL(nextAuthUrl).host;
// TODO: remove @ts-ignore
// @ts-ignore
if (siwe.domain !== nextAuthHost) {
return null;
}

if (
// TODO: remove @ts-ignore
// @ts-ignore
siwe.nonce !==
(await getCsrfToken({ req: { headers: req.headers } }))
) {
return null;
}

await siwe.verify({ signature: credentials?.signature || '' });
// TODO: remove @ts-ignore
// @ts-ignore
await siwe.verify({ signature: credentials?.signature || "" });
return {
// TODO: remove @ts-ignore
// @ts-ignore
id: siwe.address,
};
} catch (e) {
Expand All @@ -49,17 +57,17 @@ export function getAuthOptions(req: IncomingMessage): NextAuthOptions {
},
credentials: {
message: {
label: 'Message',
placeholder: '0x0',
type: 'text',
label: "Message",
placeholder: "0x0",
type: "text",
},
signature: {
label: 'Signature',
placeholder: '0x0',
type: 'text',
label: "Signature",
placeholder: "0x0",
type: "text",
},
},
name: 'Ethereum',
name: "Ethereum",
}),
];

Expand All @@ -77,7 +85,7 @@ export function getAuthOptions(req: IncomingMessage): NextAuthOptions {
providers,
secret: process.env.NEXTAUTH_SECRET,
session: {
strategy: 'jwt',
strategy: "jwt",
},
};
}
Expand All @@ -88,13 +96,13 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) {
const authOptions = getAuthOptions(req);

if (!Array.isArray(req.query.nextauth)) {
res.status(400).send('Bad request');
res.status(400).send("Bad request");
return;
}

const isDefaultSigninPage =
req.method === 'GET' &&
req.query.nextauth.find(value => value === 'signin');
req.method === "GET" &&
req.query.nextauth.find((value) => value === "signin");

// Hide Sign-In with Ethereum from default sign page
if (isDefaultSigninPage) {
Expand Down
3 changes: 0 additions & 3 deletions examples/with-next-wallet-button/.eslintrc.json

This file was deleted.

Loading

0 comments on commit b28c8dc

Please sign in to comment.