diff --git a/playground-authjs/server/api/protected/inline.ts b/playground-authjs/server/api/protected/inline.ts index 63282a59..8a7e77d9 100644 --- a/playground-authjs/server/api/protected/inline.ts +++ b/playground-authjs/server/api/protected/inline.ts @@ -1,3 +1,4 @@ +import { eventHandler } from 'h3' import { getServerSession } from '#auth' export default eventHandler(async (event) => { diff --git a/playground-authjs/server/api/protected/middleware.ts b/playground-authjs/server/api/protected/middleware.ts index 635562c1..485da1ac 100644 --- a/playground-authjs/server/api/protected/middleware.ts +++ b/playground-authjs/server/api/protected/middleware.ts @@ -1 +1,3 @@ +import { eventHandler } from 'h3' + export default eventHandler(() => ({ status: 'authenticated', text: 'you only see me if you are logged in, as a server-middleware protects me' })) diff --git a/playground-authjs/server/api/token.get.ts b/playground-authjs/server/api/token.get.ts index d70c779f..92efde8b 100644 --- a/playground-authjs/server/api/token.get.ts +++ b/playground-authjs/server/api/token.get.ts @@ -1,3 +1,4 @@ +import { eventHandler } from 'h3' import { getToken } from '#auth' export default eventHandler(event => getToken({ event })) diff --git a/playground-authjs/server/middleware/auth.ts b/playground-authjs/server/middleware/auth.ts index be391037..8b6ce9a9 100644 --- a/playground-authjs/server/middleware/auth.ts +++ b/playground-authjs/server/middleware/auth.ts @@ -1,4 +1,4 @@ -import { eventHandler } from 'h3' +import { createError, eventHandler } from 'h3' import { getServerSession } from '#auth' export default eventHandler(async (event) => { diff --git a/playground-local/server/api/auth/login.post.ts b/playground-local/server/api/auth/login.post.ts index a344dedb..0254e27f 100644 --- a/playground-local/server/api/auth/login.post.ts +++ b/playground-local/server/api/auth/login.post.ts @@ -1,3 +1,4 @@ +import { createError, eventHandler, readBody } from 'h3' import { z } from 'zod' import { sign } from 'jsonwebtoken' diff --git a/playground-local/server/api/auth/logout.post.ts b/playground-local/server/api/auth/logout.post.ts index 63938e9f..18fc27bf 100644 --- a/playground-local/server/api/auth/logout.post.ts +++ b/playground-local/server/api/auth/logout.post.ts @@ -1 +1,3 @@ +import { eventHandler } from 'h3' + export default eventHandler(() => ({ status: 'OK ' })) diff --git a/playground-local/server/api/auth/user.get.ts b/playground-local/server/api/auth/user.get.ts index 3627dfce..f4dd8ece 100644 --- a/playground-local/server/api/auth/user.get.ts +++ b/playground-local/server/api/auth/user.get.ts @@ -1,4 +1,4 @@ -import { H3Event } from 'h3' +import { createError, eventHandler, getRequestHeader, H3Event } from 'h3' import { verify } from 'jsonwebtoken' import { SECRET } from './login.post' diff --git a/playground-refresh/server/api/auth/login.post.ts b/playground-refresh/server/api/auth/login.post.ts index 488a4650..97f710bf 100644 --- a/playground-refresh/server/api/auth/login.post.ts +++ b/playground-refresh/server/api/auth/login.post.ts @@ -1,3 +1,4 @@ +import { createError, eventHandler, readBody } from 'h3' import { z } from 'zod' import { sign } from 'jsonwebtoken' diff --git a/playground-refresh/server/api/auth/logout.post.ts b/playground-refresh/server/api/auth/logout.post.ts index 63938e9f..7c0af47d 100644 --- a/playground-refresh/server/api/auth/logout.post.ts +++ b/playground-refresh/server/api/auth/logout.post.ts @@ -1 +1,3 @@ -export default eventHandler(() => ({ status: 'OK ' })) +import { eventHandler } from 'h3' + +export default eventHandler(() => ({ status: 'OK' })) diff --git a/playground-refresh/server/api/auth/refresh.post.ts b/playground-refresh/server/api/auth/refresh.post.ts index 8660a670..b3d49421 100644 --- a/playground-refresh/server/api/auth/refresh.post.ts +++ b/playground-refresh/server/api/auth/refresh.post.ts @@ -1,3 +1,4 @@ +import { createError, eventHandler, readBody } from 'h3' import { sign, verify } from 'jsonwebtoken' export const SECRET = 'dummy' diff --git a/playground-refresh/server/api/auth/user.get.ts b/playground-refresh/server/api/auth/user.get.ts index d7417a17..c5039a5e 100644 --- a/playground-refresh/server/api/auth/user.get.ts +++ b/playground-refresh/server/api/auth/user.get.ts @@ -1,4 +1,4 @@ -import { H3Event } from 'h3' +import { createError, eventHandler, getRequestHeader, H3Event } from 'h3' import { verify } from 'jsonwebtoken' import { SECRET } from './login.post' diff --git a/src/runtime/server/services/authjs/nuxtAuthHandler.ts b/src/runtime/server/services/authjs/nuxtAuthHandler.ts index 192c6556..8fdbe271 100644 --- a/src/runtime/server/services/authjs/nuxtAuthHandler.ts +++ b/src/runtime/server/services/authjs/nuxtAuthHandler.ts @@ -1,5 +1,5 @@ import type { IncomingHttpHeaders } from 'http' -import { getQuery, setCookie, readBody, appendHeader, sendRedirect, eventHandler, parseCookies, createError, isMethod, getMethod, getHeaders } from 'h3' +import { getQuery, setCookie, readBody, appendHeader, sendRedirect, eventHandler, parseCookies, createError, isMethod, getHeaders } from 'h3' import type { H3Event } from 'h3' import { AuthHandler } from 'next-auth/core' @@ -31,7 +31,7 @@ const useConfig = () => useTypedBackendConfig(useRuntimeConfig(), 'authjs') const readBodyForNext = async (event: H3Event) => { let body: any - if (isMethod(event, 'PATCH') || isMethod(event, 'POST') || isMethod(event, 'PUT') || isMethod(event, 'DELETE')) { + if (isMethod(event, ['PATCH', 'POST', 'PUT', 'DELETE'])) { body = await readBody(event) } return body @@ -54,7 +54,7 @@ const parseActionAndProvider = ({ context }: H3Event): { action: AuthAction, pro // Get TS to correctly infer the type of `unvalidatedAction` const action = SUPPORTED_ACTIONS.find(action => action === unvalidatedAction) if (!action) { - throw createError({ statusCode: 400, statusMessage: `Called endpoint with unsupported action ${unvalidatedAction!}. Only the following actions are supported: ${SUPPORTED_ACTIONS.join(', ')}` }) + throw createError({ statusCode: 400, statusMessage: `Called endpoint with unsupported action ${unvalidatedAction}. Only the following actions are supported: ${SUPPORTED_ACTIONS.join(', ')}` }) } return { action, providerId } @@ -97,7 +97,7 @@ export const NuxtAuthHandler = (nuxtAuthOptions?: AuthOptions) => { cookies: parseCookies(event), query: undefined, headers: getHeaders(event), - method: getMethod(event), + method: event.method, providerId: undefined, error: undefined }