@henosia/app-next 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,65 +1,22 @@
1
- import { randomBytes } from 'node:crypto';
2
-
3
- /**
4
- * Makes a webpack OutputFileSystem emit assets atomically.
5
- * Fixes `Uncaught SyntaxError: Invalid or unexpected token` in the browser when the
6
- * served layout.js is visibly cut off mid-string due to concurrent non-atomic writes.
7
- */
8
- function patchWebpackOutputFileSystem(ofs) {
9
- if (!ofs || ofs.__atomicEmitPatched) return;
10
- if (typeof ofs.writeFile !== 'function' || typeof ofs.rename !== 'function') {
11
- return;
12
- }
13
-
14
- const origWriteFile = ofs.writeFile.bind(ofs);
15
- const origRename = ofs.rename.bind(ofs);
16
- const origUnlink = typeof ofs.unlink === 'function' ? ofs.unlink.bind(ofs) : null;
17
-
18
- ofs.writeFile = function patchedWriteFile(filePath, content, optionsOrCb, maybeCb) {
19
- const hasOptions = typeof optionsOrCb !== 'function';
20
- const options = hasOptions ? optionsOrCb : undefined;
21
- const cb = hasOptions ? maybeCb : optionsOrCb;
22
- const tmp = `${filePath}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`;
23
-
24
- const done = (err) => {
25
- if (err) {
26
- if (origUnlink) origUnlink(tmp, () => cb(err));
27
- else cb(err);
28
- return;
29
- }
30
- origRename(tmp, filePath, cb);
31
- };
32
-
33
- if (hasOptions && options !== undefined) {
34
- origWriteFile(tmp, content, options, done);
35
- } else {
36
- origWriteFile(tmp, content, done);
37
- }
38
- };
39
-
40
- Object.defineProperty(ofs, '__atomicEmitPatched', { value: true, enumerable: false });
41
- }
42
-
43
- class AtomicEmitPlugin {
44
- apply(compiler) {
45
- // `outputFileSystem` may be assigned/replaced after `apply` runs (e.g. by
46
- // Next.js or webpack-dev-middleware), so patch lazily right before each
47
- // build's emit phase. This is idempotent thanks to `__atomicEmitPatched`.
48
- const patch = () => patchWebpackOutputFileSystem(compiler.outputFileSystem);
49
- compiler.hooks.beforeRun.tap('AtomicEmitPlugin', patch);
50
- compiler.hooks.watchRun.tap('AtomicEmitPlugin', patch);
51
- compiler.hooks.beforeCompile.tap('AtomicEmitPlugin', patch);
1
+ const henosiaPreviewTurboPackRules = {};
2
+ if (process.env.HENOSIA_LOADER_TURBOPACK_RULES) {
3
+ try {
4
+ Object.assign(henosiaPreviewTurboPackRules, JSON.parse(process.env.HENOSIA_LOADER_TURBOPACK_RULES));
5
+ } catch (e) {
6
+ console.error('[Henosia Loader] Error loading Turbopack rules', e);
52
7
  }
53
8
  }
54
9
 
55
10
  /** @type {import('next').NextConfig} */
56
11
  const nextConfig = {
57
- webpack: (config, { dev }) => {
58
- if (dev) {
59
- config.plugins.push(new AtomicEmitPlugin());
12
+ // the better-auth url is also a valid dev origin (note: next.js expects hostnames despite naming this option allowedDevOrigins)
13
+ allowedDevOrigins: process.env.BETTER_AUTH_URL ? [new URL(process.env.BETTER_AUTH_URL).hostname] : undefined,
14
+ devIndicators: false,
15
+ turbopack: {
16
+ "rules": {
17
+ ...henosiaPreviewTurboPackRules
60
18
  }
61
- return config;
62
- },
19
+ }
63
20
  };
64
21
 
65
22
  export default nextConfig;
@@ -4,7 +4,7 @@
4
4
  "private": true,
5
5
  "dependencies": {
6
6
  "__add_these__:": "",
7
- "@henosia/app-next": "^1.0.3",
7
+ "@henosia/app-next": "^1.0.10",
8
8
  "@tanstack/react-query": "^5.100.11",
9
9
  "better-auth": "1.6.11",
10
10
  "__others_omitted_for_brevity__": ""
@@ -3,7 +3,6 @@ import { HENOSIA_AUTH_SIGN_IN_PATH_NAME } from "../shared.mjs";
3
3
  import { o as isUnauthorizedException, s as verifyHenosiaAuthToken } from "../server-DvvkIB4j.mjs";
4
4
  import { headers } from "next/headers.js";
5
5
  import { cache } from "react";
6
- import { redirect } from "next/navigation.js";
7
6
  import { NextResponse } from "next/server.js";
8
7
  //#region src/auth/server-guards.ts
9
8
  async function buildRequestFromHeaders() {
@@ -41,7 +40,10 @@ const requireHenosiaAuth = cache(async () => {
41
40
  try {
42
41
  return await verifyClaims();
43
42
  } catch (error) {
44
- if (isUnauthorizedException(error)) redirect(HENOSIA_AUTH_SIGN_IN_PATH_NAME);
43
+ if (isUnauthorizedException(error)) {
44
+ const { redirect } = await import("next/navigation.js");
45
+ redirect(HENOSIA_AUTH_SIGN_IN_PATH_NAME);
46
+ }
45
47
  throw error;
46
48
  }
47
49
  });
@@ -137,7 +139,7 @@ function routeWithHenosiaAuth(handler) {
137
139
  try {
138
140
  const verified = await verifyHenosiaAuthToken(request);
139
141
  payload = verified.payload;
140
- accessToken = verified.accessTokenResponse.accessToken;
142
+ accessToken = verified.accessTokenResponse.idToken;
141
143
  } catch (error) {
142
144
  if (isUnauthorizedException(error)) return unauthorizedResponse();
143
145
  console.error(`[Henosia Auth] Unexpected error verifying token for ${request.method} ${request.nextUrl.pathname}`, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henosia/app-next",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Henosia integration for Next.js apps: Provides Henosia Auth and Henosia Platform features like app switcher",
5
5
  "author": "Henosia",
6
6
  "license": "SEE LICENSE IN LICENSE",