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

fix: add missing imports #671

Merged
merged 1 commit into from
Feb 22, 2024
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
1 change: 1 addition & 0 deletions playground-authjs/server/api/protected/inline.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { eventHandler } from 'h3'
import { getServerSession } from '#auth'

export default eventHandler(async (event) => {
Expand Down
2 changes: 2 additions & 0 deletions playground-authjs/server/api/protected/middleware.ts
Original file line number Diff line number Diff line change
@@ -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' }))
1 change: 1 addition & 0 deletions playground-authjs/server/api/token.get.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { eventHandler } from 'h3'
import { getToken } from '#auth'

export default eventHandler(event => getToken({ event }))
2 changes: 1 addition & 1 deletion playground-authjs/server/middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eventHandler } from 'h3'
import { createError, eventHandler } from 'h3'
import { getServerSession } from '#auth'

export default eventHandler(async (event) => {
Expand Down
1 change: 1 addition & 0 deletions playground-local/server/api/auth/login.post.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createError, eventHandler, readBody } from 'h3'
import { z } from 'zod'
import { sign } from 'jsonwebtoken'

Expand Down
2 changes: 2 additions & 0 deletions playground-local/server/api/auth/logout.post.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import { eventHandler } from 'h3'

export default eventHandler(() => ({ status: 'OK ' }))
2 changes: 1 addition & 1 deletion playground-local/server/api/auth/user.get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { H3Event } from 'h3'
import { createError, eventHandler, getRequestHeader, H3Event } from 'h3'
import { verify } from 'jsonwebtoken'
import { SECRET } from './login.post'

Expand Down
1 change: 1 addition & 0 deletions playground-refresh/server/api/auth/login.post.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createError, eventHandler, readBody } from 'h3'
import { z } from 'zod'
import { sign } from 'jsonwebtoken'

Expand Down
4 changes: 3 additions & 1 deletion playground-refresh/server/api/auth/logout.post.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default eventHandler(() => ({ status: 'OK ' }))
import { eventHandler } from 'h3'

export default eventHandler(() => ({ status: 'OK' }))
1 change: 1 addition & 0 deletions playground-refresh/server/api/auth/refresh.post.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createError, eventHandler, readBody } from 'h3'
import { sign, verify } from 'jsonwebtoken'

export const SECRET = 'dummy'
Expand Down
2 changes: 1 addition & 1 deletion playground-refresh/server/api/auth/user.get.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { H3Event } from 'h3'
import { createError, eventHandler, getRequestHeader, H3Event } from 'h3'
import { verify } from 'jsonwebtoken'
import { SECRET } from './login.post'

Expand Down
8 changes: 4 additions & 4 deletions src/runtime/server/services/authjs/nuxtAuthHandler.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this improvement! 🥳

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h3 seems to have improved since last update. If only the imports were not broken :D

body = await readBody(event)
}
return body
Expand All @@ -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 }
Expand Down Expand Up @@ -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
}
Expand Down
Loading