Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt 3.5.1 #7626

Merged
merged 7 commits into from
May 22, 2023
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
2 changes: 1 addition & 1 deletion apps/playgrounds/nuxt/composables/useSession.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Session } from "@auth/core"
import { Session } from "@auth/core/types"

export default function useSession() {
return useState<Session | null>("session", () => null)
Expand Down
2 changes: 1 addition & 1 deletion apps/playgrounds/nuxt/lib/auth/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function signIn<

// TODO: Handle custom base path
// TODO: Remove this since Sveltekit offers the CSRF protection via origin check
const { csrfToken } = await $fetch("/api/auth/csrf")
const { csrfToken } = await $fetch<{ csrfToken: string }>("/api/auth/csrf")

console.log(_signInUrl)

Expand Down
11 changes: 6 additions & 5 deletions apps/playgrounds/nuxt/lib/auth/server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { AuthHandler, AuthOptions, Session } from "@auth/core"
import { AuthConfig, Session } from "@auth/core/types"
import { Auth } from "@auth/core"
import { fromNodeMiddleware, H3Event } from "h3"
import getURL from "requrl"
import { createMiddleware } from "@hattip/adapter-node"

export function NuxtAuthHandler(options: AuthOptions) {
export function NuxtAuthHandler(options: AuthConfig) {
async function handler(ctx: { request: Request }) {
options.trustHost ??= true

return AuthHandler(ctx.request, options)
return Auth(ctx.request, options)
}

const middleware = createMiddleware(handler)
Expand All @@ -17,7 +18,7 @@ export function NuxtAuthHandler(options: AuthOptions) {

export async function getSession(
event: H3Event,
options: AuthOptions
options: AuthConfig
): Promise<Session | null> {
options.trustHost ??= true

Expand All @@ -30,7 +31,7 @@ export async function getSession(
nodeHeaders.append(key, headers[key] as any)
})

const response = await AuthHandler(
const response = await Auth(
new Request(url, { headers: nodeHeaders }),
options
)
Expand Down
15 changes: 8 additions & 7 deletions apps/playgrounds/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"name": "playground-nuxt",
"name": "next-auth-nuxt",
"private": true,
"scripts": {
"build": "nuxt prepare && nuxt build",
"dev": "nuxt prepare && export NODE_OPTIONS='--no-experimental-fetch' && nuxt dev",
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview"
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@nuxt/eslint-config": "^0.1.1",
"eslint": "^8.29.0",
"h3": "1.0.2",
"nuxt": "3.0.0"
"h3": "1.6.6",
"nuxt": "3.5.1"
},
"dependencies": {
"@auth/core": "workspace:*",
"@hattip/adapter-node": "^0.0.22",
"@hattip/adapter-node": "^0.0.34",
"requrl": "^3.0.2"
}
}
2 changes: 1 addition & 1 deletion apps/playgrounds/nuxt/plugins/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Session } from "@auth/core"
import { Session } from "@auth/core/types"

export default defineNuxtPlugin(async () => {
const session = useSession()
Expand Down
6 changes: 3 additions & 3 deletions apps/playgrounds/nuxt/server/api/auth/[...].ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { NuxtAuthHandler } from "@/lib/auth/server"
import GithubProvider from "@auth/core/providers/github"
import type { AuthOptions } from "@auth/core"
import type { AuthConfig } from "@auth/core"

const runtimeConfig = useRuntimeConfig()

export const authOptions: AuthOptions = {
export const authOptions = {
secret: runtimeConfig.secret,
providers: [
GithubProvider({
clientId: runtimeConfig.github.clientId,
clientSecret: runtimeConfig.github.clientSecret,
}),
],
}
} as AuthConfig

export default NuxtAuthHandler(authOptions)
Loading