Skip to content

Commit

Permalink
Remove unnecessary wrapping with NodeNext(Request|Response) (#1956)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis authored Mar 9, 2025
1 parent 5b7ff24 commit 7b72574
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import EmailProvider from 'next-auth/providers/email'
import prisma from '@/api/models'
import nodemailer from 'nodemailer'
import { PrismaAdapter } from '@auth/prisma-adapter'
import { NodeNextRequest, NodeNextResponse } from 'next/dist/server/base-http/node'
import { getToken, encode as encodeJWT } from 'next-auth/jwt'
import { datePivot } from '@/lib/time'
import { schnorr } from '@noble/curves/secp256k1'
Expand Down Expand Up @@ -130,7 +129,7 @@ function getCallbacks (req, res) {
const secret = process.env.NEXTAUTH_SECRET
const jwt = await encodeJWT({ token, secret })
const me = await prisma.user.findUnique({ where: { id: token.id } })
setMultiAuthCookies(new NodeNextRequest(req), new NodeNextResponse(res), { ...me, jwt })
setMultiAuthCookies(req, res, { ...me, jwt })
}

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

// are we trying to add a new account for switching between?
const { body } = req.body
const multiAuth = typeof body.multiAuth === 'string' ? body.multiAuth === 'true' : !!body.multiAuth
const multiAuth = typeof req.body.multiAuth === 'string' ? req.body.multiAuth === 'true' : !!req.body.multiAuth

try {
// does the given challenge (k1) exist in our db?
Expand Down Expand Up @@ -262,7 +260,7 @@ const getProviders = res => [
k1: { label: 'k1', type: 'text' }
},
authorize: async (credentials, req) => {
return await pubkeyAuth(credentials, new NodeNextRequest(req), new NodeNextResponse(res), 'pubkey')
return await pubkeyAuth(credentials, req, res, 'pubkey')
}
}),
CredentialsProvider({
Expand All @@ -273,7 +271,7 @@ const getProviders = res => [
},
authorize: async ({ event }, req) => {
const credentials = await nostrEventAuth(event)
return await pubkeyAuth(credentials, new NodeNextRequest(req), new NodeNextResponse(res), 'nostrAuthPubkey')
return await pubkeyAuth(credentials, req, res, 'nostrAuthPubkey')
}
}),
GitHubProvider({
Expand Down
7 changes: 7 additions & 0 deletions pages/api/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ApolloServerPluginLandingPageLocalDefault,
ApolloServerPluginLandingPageProductionDefault
} from '@apollo/server/plugin/landingPage/default'
import { NodeNextRequest } from 'next/dist/server/base-http/node'

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

if (!request.cookies) {
// required to properly access parsed cookies via request.cookies
// and not unparsed via request.headers.cookie
request = new NodeNextRequest(request)
}

// is there a cookie pointer?
const cookiePointerName = 'multi_auth.user-id'
const hasCookiePointer = !!request.cookies[cookiePointerName]
Expand Down

0 comments on commit 7b72574

Please sign in to comment.