Open nlaurie opened 1 month ago
Did this happen in latest version?
Just updated to the latest today , and it still doesn't work in azure.
The result is server side the middleware is not decoding the session and filling in the auth context.
I wrote a custom middleware that decodes the session cookie and and uses the verifyToken function, so I know the everything is where it should be client side.
// import { eventHandler, fromNodeMiddleware, getRequestProtocol } from 'h3'
// import type { EventHandler, H3Event, NodeMiddleware } from 'h3'
// import { signedOutAuthObject, signedInAuthObject } from '@clerk/backend/internal'
// import { authenticateRequest } from '@clerk/backend'
import { verifyToken } from '@clerk/clerk-sdk-node'
// import { signedOutAuthObject } from '@clerk/backend'
// import { ClerkMiddlewareOptions } from '@clerk/clerk-sdk-node'
// import clerk from '@clerk/clerk-sdk-node'
import type { JwtPayload } from '@clerk/types'
// import { withClerkMiddleware } from 'h3-clerk'
export interface ApplicationClerkJwtPayload extends JwtPayload {
av_p_uuid: string
email?: string
}
export default defineEventHandler(async (event) => {
event.context.auth2 = { userId: null, userUuid: null }
let payload: ApplicationClerkJwtPayload | undefined = undefined
const jwt = getCookie(event, '__session')
if (jwt) {
// * Decode Token -----------------------------------
try {
payload = (await verifyToken(jwt, { secretKey: useRuntimeConfig().clerkSecretKey })) as ApplicationClerkJwtPayload
// console.log(payload)
} catch (error) {
console.error(error)
}
}
if (payload && payload.sub) {
event.context.auth2 = { userId: payload.sub, userUuid: '' }
}
// event.context.auth = { user: 123 }
})
// export default withClerkMiddleware()
declare module 'h3' {
interface H3EventContext {
auth2: { userId: string | null; userUuid: string | null }
}
}
I have clerk and vue-clerk running , everything runs great locally. however when deploying my nuxt site to azure swa , it seems like h3-clerk is not working correctly on the server side. Are there any known issues related to this.
Regards Nick