Skip to content

Commit 7b72574

Browse files
authored
Remove unnecessary wrapping with NodeNext(Request|Response) (#1956)
1 parent 5b7ff24 commit 7b72574

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

pages/api/auth/[...nextauth].js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import EmailProvider from 'next-auth/providers/email'
77
import prisma from '@/api/models'
88
import nodemailer from 'nodemailer'
99
import { PrismaAdapter } from '@auth/prisma-adapter'
10-
import { NodeNextRequest, NodeNextResponse } from 'next/dist/server/base-http/node'
1110
import { getToken, encode as encodeJWT } from 'next-auth/jwt'
1211
import { datePivot } from '@/lib/time'
1312
import { schnorr } from '@noble/curves/secp256k1'
@@ -130,7 +129,7 @@ function getCallbacks (req, res) {
130129
const secret = process.env.NEXTAUTH_SECRET
131130
const jwt = await encodeJWT({ token, secret })
132131
const me = await prisma.user.findUnique({ where: { id: token.id } })
133-
setMultiAuthCookies(new NodeNextRequest(req), new NodeNextResponse(res), { ...me, jwt })
132+
setMultiAuthCookies(req, res, { ...me, jwt })
134133
}
135134

136135
return token
@@ -180,8 +179,7 @@ async function pubkeyAuth (credentials, req, res, pubkeyColumnName) {
180179
const { k1, pubkey } = credentials
181180

182181
// are we trying to add a new account for switching between?
183-
const { body } = req.body
184-
const multiAuth = typeof body.multiAuth === 'string' ? body.multiAuth === 'true' : !!body.multiAuth
182+
const multiAuth = typeof req.body.multiAuth === 'string' ? req.body.multiAuth === 'true' : !!req.body.multiAuth
185183

186184
try {
187185
// does the given challenge (k1) exist in our db?
@@ -262,7 +260,7 @@ const getProviders = res => [
262260
k1: { label: 'k1', type: 'text' }
263261
},
264262
authorize: async (credentials, req) => {
265-
return await pubkeyAuth(credentials, new NodeNextRequest(req), new NodeNextResponse(res), 'pubkey')
263+
return await pubkeyAuth(credentials, req, res, 'pubkey')
266264
}
267265
}),
268266
CredentialsProvider({
@@ -273,7 +271,7 @@ const getProviders = res => [
273271
},
274272
authorize: async ({ event }, req) => {
275273
const credentials = await nostrEventAuth(event)
276-
return await pubkeyAuth(credentials, new NodeNextRequest(req), new NodeNextResponse(res), 'nostrAuthPubkey')
274+
return await pubkeyAuth(credentials, req, res, 'nostrAuthPubkey')
277275
}
278276
}),
279277
GitHubProvider({

pages/api/graphql.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ApolloServerPluginLandingPageLocalDefault,
1212
ApolloServerPluginLandingPageProductionDefault
1313
} from '@apollo/server/plugin/landingPage/default'
14+
import { NodeNextRequest } from 'next/dist/server/base-http/node'
1415

1516
const apolloServer = new ApolloServer({
1617
typeDefs,
@@ -85,6 +86,12 @@ export default startServerAndCreateNextHandler(apolloServer, {
8586
export function multiAuthMiddleware (request) {
8687
// switch next-auth session cookie with multi_auth cookie if cookie pointer present
8788

89+
if (!request.cookies) {
90+
// required to properly access parsed cookies via request.cookies
91+
// and not unparsed via request.headers.cookie
92+
request = new NodeNextRequest(request)
93+
}
94+
8895
// is there a cookie pointer?
8996
const cookiePointerName = 'multi_auth.user-id'
9097
const hasCookiePointer = !!request.cookies[cookiePointerName]

0 commit comments

Comments
 (0)