bnason
bnason
Explore posts from servers
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
Now to get that body parser only on that route
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
aha! export default fromNodeMiddleware(bodyParser.urlencoded({ extended: false }))
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
ok I don't know why it's looking at the body... the damn thing is urlencoded!
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
Weird, even using a normal event handler, the body is { '{}': '' }
export default defineEventHandler(async (event) => {
const body = await readBody(event)
console.log(JSON.stringify(body))
})
export default defineEventHandler(async (event) => {
const body = await readBody(event)
console.log(JSON.stringify(body))
})
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
export default fromNodeMiddleware(bodyParser.text())
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
I even installed bodyParser as a server middleware but that just gives me an empty object {} instead of undefined
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
nope =\
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
hmm i bet its the async
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
import jwt from 'jsonwebtoken'

import { identityProvider, serviceProvider } from '~/server/utils/saml'

export default fromNodeMiddleware(async (request, response) => {
try {
const { extract } = await serviceProvider.parseLoginResponse(identityProvider, 'post', request)
const { session } = extract.attributes

const cookie = jwt.sign(session, process.env.SESSION_SECRET || 'foobar', { expiresIn: '1h' })

// setCookie(event, 'SESSION', cookie)
} catch (e) {
console.error('[FATAL] when parsing login response sent from IdP', e)
}
})
import jwt from 'jsonwebtoken'

import { identityProvider, serviceProvider } from '~/server/utils/saml'

export default fromNodeMiddleware(async (request, response) => {
try {
const { extract } = await serviceProvider.parseLoginResponse(identityProvider, 'post', request)
const { session } = extract.attributes

const cookie = jwt.sign(session, process.env.SESSION_SECRET || 'foobar', { expiresIn: '1h' })

// setCookie(event, 'SESSION', cookie)
} catch (e) {
console.error('[FATAL] when parsing login response sent from IdP', e)
}
})
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
its expecting request.body to exist
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
Same code as above: const { extract } = await serviceProvider.parseLoginResponse(identityProvider, 'post', request)
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
does fromNodeMiddleware parse the body or do I need to install the express bodyParser somehow?
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
no I haven't
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
Ok so it looks like the error I'm getting is because request.body is undefined
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
const { extract } = await serviceProvider.parseLoginResponse(identityProvider, 'post', event.node.req)
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Express compatible request object
yea I'm using event.node.req right now. Is toNodeMiddleware avaiable in v3.12 with v4 compatibilityVersion set?
27 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Create new v4 app
oh nice!
8 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Create new v4 app
yup i watched that 🙂 though since this is a fresh app, I don't really need any granular control of features. i specifically want to test out the new version 🙂
8 replies
NNuxt
Created by bnason on 6/21/2024 in #❓・help
Create new v4 app
I suppose its just a v3 template but adding future: { compatibilityVersion: 4 }, to the nuxt.config.ts now with v3.12
8 replies