umaU
Convex Community10mo ago
59 replies
uma

callback, 3rd party authentication, convexAuth

I am running into a problem with Figma Oauth 2.0 callback which returns with ?code=&state= appended to the return URL. Now, the ?code part of it is getting consumed by ConvexAuth. I'd love some help on getting around it.

I edited my middleware.ts to do the following:
export default convexAuthNextjsMiddleware((request) => {
  const url = new URL(request.url)
  console.log('Middleware full URL:', url.href)
  // Intercept the Figma callback route to rewrite "code" as "figmaCode"
  if (url.pathname.startsWith('/settings/profile/figma-auth-callback') && url.searchParams.has('code')) {
    const code = url.searchParams.get('code')!
    url.searchParams.delete('code')
    url.searchParams.set('figmaCode', code)
    // Redirect to the same URL with the renamed query parameter.
    return NextResponse.redirect(url)
  }
  if (!isPublicPage(request as NextRequest) && !isAuthenticatedNextjs()) {
    return nextjsMiddlewareRedirect(request as NextRequest, '/auth')
  }
})

But that doesn't fix it either.

I couldn't use this workaround because I am not using tanstack server:
https://github.com/get-convex/convex-auth/issues/145

The work around would be to break out a chunk of code out from ConvexAuthNextjsServerProvider and that is painful.

Integration with a third party is common, so what could I be missing? This has to be solved elegantly. A movement on this thread: https://github.com/get-convex/convex-auth/issues/145 as suggested by @ballingt and @sshader would work.
GitHub
Came across this curious case recently: A user is created and authenticated through Convex Auth, no problem, no sweat. As a business rule, that user needs to be able to connect a Mailchimp account ...
Convex Auth consumes pages that have "code" as search param · Issu...
Was this page helpful?