Skip to content

Commit

Permalink
refactor(routing): ♻️ Optimized redirect handling
Browse files Browse the repository at this point in the history
  • Loading branch information
itpropro committed Sep 19, 2024
1 parent f0baa44 commit 73c366e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 36 deletions.
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"@iconify-json/simple-icons": "^1.2.3",
"@nuxtjs/color-mode": "^3.5.1",
"@unocss/nuxt": "^0.62.4",
"nuxt-oidc-auth": "^0.13.0"
"nuxt-oidc-auth": "workspace:^"
}
}
27 changes: 2 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { OidcProviderConfig, ProviderConfigs, ProviderKeys } from './runtim
import type { AuthSessionConfig } from './runtime/types/session'
import type { ProviderInfo } from './types'
import { extendServerRpc, onDevToolsInitialized } from '@nuxt/devtools-kit'
import { addImportsDir, addPlugin, addRouteMiddleware, addServerHandler, addServerPlugin, createResolver, defineNuxtModule, useLogger } from '@nuxt/kit'
import { addImportsDir, addPlugin, addRouteMiddleware, addServerHandler, addServerPlugin, createResolver, defineNuxtModule, extendRouteRules, useLogger } from '@nuxt/kit'
import { defu } from 'defu'
import { setupDevToolsUI } from './devtools'
import * as providerPresets from './runtime/providers'
Expand Down Expand Up @@ -215,10 +215,11 @@ export default defineNuxtModule<ModuleOptions>({

// Add default provider routes
if (process.env.NODE_ENV && !process.env.NODE_ENV.toLowerCase().startsWith('prod') && options.devMode?.enabled) {
addServerHandler({
handler: resolve('./runtime/server/handler/dev'),
route: '/auth/login',
method: 'get',
extendRouteRules('/auth/login', {
redirect: {
to: '/auth/dev/login',
statusCode: 302,
},
})
addServerHandler({
handler: resolve('./runtime/server/handler/logout.get'),
Expand All @@ -228,14 +229,15 @@ export default defineNuxtModule<ModuleOptions>({
}
else {
if (options.defaultProvider && !options.middleware.customLoginPage) {
addServerHandler({
handler: resolve('./runtime/server/handler/login.get'),
route: `/auth/${options.defaultProvider}/login`,
method: 'get',
extendRouteRules('/auth/login', {
redirect: {
to: `/auth/${options.defaultProvider}/login`,
statusCode: 302,
},
})
addServerHandler({
handler: resolve('./runtime/server/handler/logout.get'),
route: `/auth/${options.defaultProvider}/logout`,
route: `/auth/logout`,
method: 'get',
})
}
Expand Down

0 comments on commit 73c366e

Please sign in to comment.