Skip to content

Commit

Permalink
refactor(nuxt): Separate module config from AuthConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbud committed Apr 22, 2024
1 parent d801b3e commit b78106f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apps/dev/nuxt/server/routes/auth/[...].ts
@@ -1,12 +1,12 @@
import { NuxtAuthHandler } from "#auth"
import type { NuxtAuthConfig } from "@auth/nuxt"
import type { AuthConfig } from "@auth/nuxt"
import Credentials from "@auth/nuxt/providers/credentials"
import GitHub from "@auth/nuxt/providers/github"
import Discord from "@auth/nuxt/providers/discord"

const runtimeConfig = useRuntimeConfig()

const authConfig: NuxtAuthConfig = {
const authConfig: AuthConfig = {
...runtimeConfig.authJs,
secret: runtimeConfig.auth.secret,

Expand Down
9 changes: 4 additions & 5 deletions packages/frameworks-nuxt/src/module.ts
Expand Up @@ -8,7 +8,6 @@ import {
useLogger,
} from "@nuxt/kit"
import { defu } from "defu"
import type { AuthConfig } from "@auth/core"

const configKey = "authJs" as const

Expand All @@ -21,13 +20,15 @@ export type {
User,
} from "@auth/core/types"

export type { AuthConfig } from "@auth/core"

export interface MiddlewareConfig {
globalUnauthenticatedRedirectTo?: string
}

/** Configure the {@link defineNuxtModule} method. */
export interface NuxtAuthConfig extends Omit<AuthConfig, "raw"> {
baseUrl?: string
export interface NuxtAuthConfig {
basePath?: string
middleware?: MiddlewareConfig
}

Expand Down Expand Up @@ -191,8 +192,6 @@ export default defineNuxtModule<NuxtAuthConfig>({

// Default configuration options
defaults: {
providers: [],
baseUrl: "",
basePath: "/auth",
middleware: {
globalUnauthenticatedRedirectTo: undefined,
Expand Down
4 changes: 2 additions & 2 deletions packages/frameworks-nuxt/src/runtime/lib/server.ts
@@ -1,5 +1,5 @@
import { Auth } from "@auth/core"
import type { NuxtAuthConfig } from "../../module"
import type { AuthConfig } from "@auth/core"
import { getRequestFromEvent, getBasePath } from "../utils"
import { defineEventHandler } from "h3"
import type { H3Event } from "h3"
Expand All @@ -21,7 +21,7 @@ import type { Session } from "@auth/core/types"
* @param config AuthConfig
* @returns EventHandler
*/
export function NuxtAuthHandler(config: NuxtAuthConfig) {
export function NuxtAuthHandler(config: AuthConfig) {
return defineEventHandler(async (event) => {
/**
* If the request is a prerender request, do nothing.
Expand Down

0 comments on commit b78106f

Please sign in to comment.