Skip to content

Commit

Permalink
Merge branch 'main' into feat/json-pointer-extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
zoey-kaiser authored Feb 23, 2024
2 parents f7fde1f + b49aa78 commit cd55182
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 8 deletions.
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'])) {
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

0 comments on commit cd55182

Please sign in to comment.