Skip to content
Merged
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
9 changes: 9 additions & 0 deletions .changeset/lemon-trams-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@asgardeo/browser': patch
'@asgardeo/nuxt': patch
---

Fix SSR compatibility and module bundling issues

- **Browser:** Fixed Node.js ESM import resolution by changing directory imports (`'buffer/'`) to explicit file paths (`'buffer/index.js'`)
- **Nuxt:** Fixed Rollup bundling by centralizing module augmentations in `module.ts` and removing `.d.ts` file from dist
6 changes: 3 additions & 3 deletions packages/browser/esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ const polyfillPlugin = {

// Buffer polyfill
build.onResolve({filter: /^buffer$/}, () => ({
path: require.resolve('buffer/'),
path: require.resolve('buffer/index.js'),
}));
},
};

const commonOptions = {
banner: {
js: `
import { Buffer } from 'buffer/';
import { Buffer } from 'buffer/index.js';
if (typeof window !== 'undefined' && !window.Buffer) {
window.Buffer = Buffer;
}
Expand All @@ -66,7 +66,7 @@ const commonOptions = {
footer: {
js: `
if (typeof window !== 'undefined' && !window.Buffer) {
window.Buffer = require('buffer/').Buffer;
window.Buffer = require('buffer/index.js').Buffer;
}
`,
},
Expand Down
2 changes: 0 additions & 2 deletions packages/nuxt/.npmignore

This file was deleted.

20 changes: 18 additions & 2 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from '@nuxt/kit';
import type {Nuxt} from '@nuxt/schema';
import {defu} from 'defu';
import type {AsgardeoNuxtConfig} from './runtime/types';
import type {AsgardeoNuxtConfig, AsgardeoSessionPayload, AsgardeoSSRData} from './runtime/types';

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

Expand Down Expand Up @@ -298,14 +298,20 @@ export default defineNuxtModule<AsgardeoNuxtConfig>({
});

declare module '@nuxt/schema' {
interface NuxtConfig {
asgardeo?: AsgardeoNuxtConfig;
}
interface NuxtOptions {
asgardeo?: AsgardeoNuxtConfig;
}
interface PublicRuntimeConfig {
asgardeo: {
afterSignInUrl: string;
afterSignOutUrl: string;
applicationId?: string;
baseUrl: string;
clientId: string;
preferences?: import('./runtime/types').AsgardeoNuxtConfig['preferences'];
preferences?: AsgardeoNuxtConfig['preferences'];
scopes: string[];
signInUrl?: string;
signUpUrl?: string;
Expand All @@ -319,3 +325,13 @@ declare module '@nuxt/schema' {
};
}
}

declare module 'h3' {
interface H3EventContext {
asgardeo?: {
isSignedIn?: boolean;
session?: AsgardeoSessionPayload | {sub?: string} | null;
ssr?: AsgardeoSSRData;
};
}
}
7 changes: 3 additions & 4 deletions packages/nuxt/src/runtime/plugins/asgardeo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ import type {AsgardeoAuthState, AsgardeoSSRData} from '../types';
import {defineNuxtPlugin, useState, useRequestEvent, useRuntimeConfig, navigateTo} from '#app';
import type {NuxtApp} from '#app';

// Import H3 augmentation so event.context.asgardeo is typed
import '../types/augments.d';

/**
* Universal Nuxt plugin (runs on both server and client) that wires up the
* Asgardeo Vue SDK.
Expand Down Expand Up @@ -122,7 +119,9 @@ export default defineNuxtPlugin((nuxtApp: NuxtApp) => {
brandingState.value = ssr.brandingPreference;
} else {
// Backwards-compat: fall back to the legacy context shape (pre-Step-2 plugin).
const ssrContext: {isSignedIn?: boolean; session?: {sub?: string}} | undefined = event?.context?.asgardeo;
const ssrContext: {isSignedIn?: boolean; session?: {sub?: string}} | undefined = event?.context?.asgardeo as
| {isSignedIn?: boolean; session?: {sub?: string}}
| undefined;
if (ssrContext) {
authState.value = {
isLoading: false,
Expand Down
3 changes: 0 additions & 3 deletions packages/nuxt/src/runtime/server/plugins/asgardeo-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import AsgardeoNuxtClient from '../AsgardeoNuxtClient';
import {verifyAndRehydrateSession} from '../utils/serverSession';
import {useRuntimeConfig} from '#imports';

// Import augmentation so event.context.asgardeo is typed
import '../../types/augments.d';

const log: ReturnType<typeof createLogger> = createLogger('asgardeo-ssr');

const CALLBACK_PATH: string = '/api/auth/callback';
Expand Down
61 changes: 0 additions & 61 deletions packages/nuxt/src/runtime/types/augments.d.ts

This file was deleted.

Loading