mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
added nextjs detection and added exception for auth redirection to also work inside stackblitz
This commit is contained in:
@@ -11,3 +11,4 @@ export * from "./crypto";
|
||||
export * from "./uuid";
|
||||
export { FromSchema } from "./typebox/from-schema";
|
||||
export * from "./test";
|
||||
export * from "./runtime";
|
||||
|
||||
41
app/src/core/utils/runtime.ts
Normal file
41
app/src/core/utils/runtime.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { getRuntimeKey as honoGetRuntimeKey } from "hono/adapter";
|
||||
|
||||
/**
|
||||
* Adds additional checks for nextjs
|
||||
*/
|
||||
export function getRuntimeKey(): string {
|
||||
const global = globalThis as any;
|
||||
|
||||
// Detect Next.js server-side runtime
|
||||
if (global?.process?.env?.NEXT_RUNTIME === "nodejs") {
|
||||
return "nextjs";
|
||||
}
|
||||
|
||||
// Detect Next.js edge runtime
|
||||
if (global?.process?.env?.NEXT_RUNTIME === "edge") {
|
||||
return "nextjs-edge";
|
||||
}
|
||||
|
||||
// Detect Next.js client-side runtime
|
||||
// @ts-ignore
|
||||
if (typeof window !== "undefined" && window.__NEXT_DATA__) {
|
||||
return "nextjs-client";
|
||||
}
|
||||
|
||||
return honoGetRuntimeKey();
|
||||
}
|
||||
|
||||
const features = {
|
||||
// supports the redirect of not full qualified addresses
|
||||
// not supported in nextjs
|
||||
redirects_non_fq: true
|
||||
};
|
||||
|
||||
export function runtimeSupports(feature: keyof typeof features) {
|
||||
const runtime = getRuntimeKey();
|
||||
if (runtime.startsWith("nextjs")) {
|
||||
features.redirects_non_fq = false;
|
||||
}
|
||||
|
||||
return features[feature];
|
||||
}
|
||||
Reference in New Issue
Block a user