Skip to content

Commit 54e0a6b

Browse files
committed
fixing a further typing bug where pages and app router types are returns as optional rather than static
1 parent 92e10f4 commit 54e0a6b

File tree

11 files changed

+30
-46
lines changed

11 files changed

+30
-46
lines changed

examples/app-router/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/drizzle/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/kv/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/plain-js/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prisma/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ui-app-router/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ui-pages-router/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-auth-pubkey",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"type": "module",
55
"description": "A light-weight Lightning and Nostr auth provider for your Next.js app that's entirely self-hosted and plugs seamlessly into the next-auth framework.",
66
"license": "ISC",

src/main/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { OAuthConfig } from "next-auth/providers/oauth";
33

44
import { formatConfig, UserConfig } from "./config/index";
55
import { NextRequest, NextResponse } from "next/server";
6-
import pubkeyHandler from "./utils/handlers";
6+
import getHandler, { appHandler, pagesHandler } from "./utils/handlers";
77

88
const lightningLogo =
99
"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjgyIiBoZWlnaHQ9IjI4MiIgdmlld0JveD0iMCAwIDI4MiAyODIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiPgo8Y2lyY2xlIGN4PSIxNDAuOTgzIiBjeT0iMTQxLjAwMyIgcj0iMTQxIiBmaWxsPSIjN0IxQUY3Ii8+CjxwYXRoIGQ9Ik03OS43NjA5IDE0NC4wNDdMMTczLjc2MSA2My4wNDY2QzE3Ny44NTcgNjAuNDIzNSAxODEuNzYxIDYzLjA0NjYgMTc5LjI2MSA2Ny41NDY2TDE0OS4yNjEgMTI2LjU0N0gyMDIuNzYxQzIwMi43NjEgMTI2LjU0NyAyMTEuMjYxIDEyNi41NDcgMjAyLjc2MSAxMzMuNTQ3TDExMC4yNjEgMjE1LjA0N0MxMDMuNzYxIDIyMC41NDcgOTkuMjYxIDIxNy41NDcgMTAzLjc2MSAyMDkuMDQ3TDEzMi43NjEgMTUxLjU0N0g3OS43NjA5Qzc5Ljc2MDkgMTUxLjU0NyA3MS4yNjA5IDE1MS41NDcgNzkuNzYwOSAxNDQuMDQ3WiIgZmlsbD0id2hpdGUiLz4KPC9nPgo8ZGVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMCI+CjxyZWN0IHdpZHRoPSIyODIiIGhlaWdodD0iMjgyIiBmaWxsPSJ3aGl0ZSIvPgo8L2NsaXBQYXRoPgo8L2RlZnM+Cjwvc3ZnPgo=";
@@ -97,10 +97,10 @@ export default function NextAuthPubkey(userConfig: UserConfig) {
9797
lightningProvider,
9898
nostrProvider,
9999
handler: async (req: NextApiRequest, res: NextApiResponse) =>
100-
pubkeyHandler({ type: "pages", req, res, config }),
100+
pagesHandler(req, res, config, getHandler({ req, res, config })),
101101
GET: async (req: NextRequest) =>
102-
pubkeyHandler({ type: "app", req, config }),
102+
appHandler(req, config, getHandler({ req, config })),
103103
POST: async (req: NextRequest) =>
104-
pubkeyHandler({ type: "app", req, config }),
104+
appHandler(req, config, getHandler({ req, config })),
105105
};
106106
}

src/main/utils/handlers.ts

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -249,63 +249,47 @@ export async function appHandler(
249249
}
250250

251251
type Arguments = {
252-
type: "pages" | "app";
253252
config: Config;
254253
req: NextApiRequest | NextRequest;
255254
res?: NextApiResponse;
256255
};
257256

258-
export default async function pubkeyHandler(args: Arguments) {
259-
const { type, req, res, config } = args;
257+
export default function getHandler(args: Arguments) {
258+
const { req, res, config } = args;
260259

261260
// get path from either pages or app router req/res objects
262261
const path = (res as any)?.params
263262
? new URL((req as NextRequest).nextUrl).pathname
264263
: (req as any)?.url.replace(config.baseUrl, "");
265264

266-
console.log(path);
267-
268265
let handler;
269266
if (path?.indexOf(config.apis.create) === 0) {
270-
handler = createHandler;
267+
return createHandler;
271268
} else if (path?.indexOf(config.apis.poll) === 0) {
272-
handler = pollHandler;
269+
return pollHandler;
273270
} else if (path?.indexOf(config.apis.callback) === 0) {
274-
handler = callbackHandler;
271+
return callbackHandler;
275272
} else if (path?.indexOf(config.apis.token) === 0) {
276-
handler = tokenHandler;
273+
return tokenHandler;
277274
} else if (path?.indexOf(config.apis.lightningSignIn) === 0) {
278-
handler = lightningSignInHandler;
275+
return lightningSignInHandler;
279276
} else if (path?.indexOf(config.apis.nostrSignIn) === 0) {
280-
handler = nostrSignInHandler;
277+
return nostrSignInHandler;
281278
} else if (path?.indexOf(config.apis.avatar) === 0) {
282-
handler = avatarHandler;
279+
return avatarHandler;
283280
} else if (path?.indexOf(config.apis.qr) === 0) {
284-
handler = qrHandler;
281+
return qrHandler;
285282
} else if (
286283
path?.indexOf(config.apis.diagnostics) === 0 &&
287284
config.flags.diagnostics
288285
) {
289-
handler = diagnosticsHandler;
286+
return diagnosticsHandler;
290287
}
291288

292-
if (!handler) {
293-
handler = async function ({}: HandlerArguments): Promise<HandlerReturn> {
294-
return {
295-
error: "NotFound",
296-
status: 404,
297-
};
289+
return async function ({}: HandlerArguments): Promise<HandlerReturn> {
290+
return {
291+
error: "NotFound",
292+
status: 404,
298293
};
299-
}
300-
301-
if (type === "pages") {
302-
return await pagesHandler(
303-
req as NextApiRequest,
304-
res as NextApiResponse,
305-
config,
306-
handler
307-
);
308-
} else {
309-
return await appHandler(req as NextRequest, config, handler);
310-
}
294+
};
311295
}

0 commit comments

Comments
 (0)