Skip to content

Commit fab3bc1

Browse files
committed
feat(nuxt): add alias to enable import in server api
1 parent c6a0469 commit fab3bc1

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

packages/nuxt/playground/nuxt.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
export default defineNuxtConfig({
2-
imports: {
3-
autoImport: false,
4-
},
52
modules: ['../src/module'],
63
devtools: { enabled: true },
74
compatibilityDate: '2024-12-26',
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { logtoEventHandler } from '#logto';
2+
3+
export default defineEventHandler(async (event) => {
4+
const config = useRuntimeConfig(event);
5+
await logtoEventHandler(event, config);
6+
const accessToken = await event.context.logtoClient.getAccessToken();
7+
return { accessToken };
8+
});

packages/nuxt/src/module.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ const logtoModule: NuxtModule<LogtoRuntimeConfigInput> = defineNuxtModule<LogtoR
4646
});
4747

4848
addImportsDir(resolve('./runtime/composables'));
49+
50+
nuxt.hook('nitro:config', (nitroConfig) => {
51+
// eslint-disable-next-line @silverhand/fp/no-mutation
52+
nitroConfig.alias ||= {};
53+
// eslint-disable-next-line @silverhand/fp/no-mutation
54+
nitroConfig.alias['#logto'] = resolve('./runtime/utils/handler.js');
55+
});
4956
},
5057
});
5158

0 commit comments

Comments
 (0)