Skip to content

Commit

Permalink
chore: prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
magiziz committed May 22, 2024
1 parent b28c8dc commit 6ef8596
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions examples/with-next-siwe-iron-session/pages/api/verify.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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);
Expand All @@ -19,7 +19,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
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 @@ -29,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
38 changes: 19 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 Down Expand Up @@ -45,7 +45,7 @@ export function getAuthOptions(req: IncomingMessage): NextAuthOptions {

// TODO: remove @ts-ignore
// @ts-ignore
await siwe.verify({ signature: credentials?.signature || "" });
await siwe.verify({ signature: credentials?.signature || '' });
return {
// TODO: remove @ts-ignore
// @ts-ignore
Expand All @@ -57,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 @@ -85,7 +85,7 @@ export function getAuthOptions(req: IncomingMessage): NextAuthOptions {
providers,
secret: process.env.NEXTAUTH_SECRET,
session: {
strategy: "jwt",
strategy: 'jwt',
},
};
}
Expand All @@ -96,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

0 comments on commit 6ef8596

Please sign in to comment.