Skip to content

Commit

Permalink
chore(playgrounds): Nuxt 3.5.1 (#7626)
Browse files Browse the repository at this point in the history
* bump Nuxt to 3.5.1

* follow playground package names

* chore: update nuxt playground scripts

* fix: imports and types

* fix: more nuxt type imports

* fix: nuxt auth options types

* fix: nuxt client fetch types
  • Loading branch information
wobsoriano authored and balazsorban44 committed Jun 1, 2023
1 parent c69a157 commit 8b3f069
Show file tree
Hide file tree
Showing 7 changed files with 9,600 additions and 6,699 deletions.
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

0 comments on commit 8b3f069

Please sign in to comment.