Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions packages/browser/esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ const polyfillPlugin = {
};

const commonOptions = {
banner: {
js: `
import { Buffer } from 'buffer/index.js';
if (typeof window !== 'undefined' && !window.Buffer) {
window.Buffer = Buffer;
}
`,
},
bundle: true,
define: {
global: 'globalThis', // Required by crypto-browserify
Expand All @@ -63,13 +55,6 @@ const commonOptions = {
},
entryPoints: ['src/index.ts'],
external: externalDeps,
footer: {
js: `
if (typeof window !== 'undefined' && !window.Buffer) {
window.Buffer = require('buffer/index.js').Buffer;
}
`,
},
platform: 'browser',
plugins: [
polyfillPlugin,
Expand Down
11 changes: 11 additions & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
/**
* Entry point for all public APIs of this SDK.
*/

// Expose Buffer globally so that browser environments that check window.Buffer
// (e.g. libraries that guard against missing Node polyfills) can find it.
// `buffer` is bundled inline by esbuild — no external import appears in the dist.
// eslint-disable-next-line import/no-cycle
import {Buffer} from 'buffer';

if (typeof window !== 'undefined' && !(window as any).Buffer) {
(window as any).Buffer = Buffer;
}

// eslint-disable-next-line import/no-cycle
export * from './__legacy__/client';
// eslint-disable-next-line import/no-cycle
Expand Down
32 changes: 32 additions & 0 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ import {
addServerPlugin,
createResolver,
defineNuxtModule,
extendViteConfig,
} from '@nuxt/kit';
import type {Nuxt} from '@nuxt/schema';
import {defu} from 'defu';
import type {AsgardeoNuxtConfig, AsgardeoSessionPayload, AsgardeoSSRData} from './runtime/types';

type ViteUserConfig = Parameters<Parameters<typeof extendViteConfig>[0]>[0];

const PACKAGE_NAME: string = '@asgardeo/nuxt';

type ServerRoute = {
Expand Down Expand Up @@ -294,6 +297,35 @@ export default defineNuxtModule<AsgardeoNuxtConfig>({

// ── Auth callback ────────────────────────────────────────────────────────
addComponent({filePath: resolve('./runtime/components/auth/Callback'), name: 'AsgardeoCallback'});

// Tell Vite to pre-bundle the CJS-only packages that @asgardeo/browser,
// @asgardeo/javascript, and @asgardeo/vue carry as external dependencies.
// Without this, Vite serves them raw from disk via @fs URLs and fails with
// "Export 'X' is not defined in module" errors when installed from npm.
// This is only needed for the client Vite build; Nitro handles the server.
extendViteConfig(
(viteConfig: ViteUserConfig) => {
const deps: string[] = [
'@asgardeo/browser',
'@asgardeo/javascript',
'@asgardeo/vue',
'base64url',
'cross-fetch',
'fast-sha256',
];

const existingInclude: string[] = (viteConfig.optimizeDeps?.include as string[]) ?? [];
const newDeps: string[] = deps.filter((dep: string) => !existingInclude.includes(dep));

Object.assign(viteConfig, {
optimizeDeps: {
...viteConfig.optimizeDeps,
include: [...existingInclude, ...newDeps],
},
});
},
{client: true},
);
},
});

Expand Down
Loading