Calling public trpc procedure redirects user to custom signin, causing an infinite loop

I have a custom sign in page, set up with next-auth middleware. This sign in page calls a public procedure of a trpc router. It loops forever until crash. Enabling DEBUG=* I see that there is a loop because the public trpc route seems to redirect to the sign in page, which then calls the procedure, which then redirects again, so on. All SSR. The proc is just returning a simple static object so wondering how a next auth redirect got in the mix.
1 Reply
blinkblinko
blinkblinkoOP9mo ago
Same if I use the next api whats goin on... Im gunna have to roll back eugh Hmm issue open since 2022 Fixed with
import { type NextRequest, NextResponse } from 'next/server';
import { withAuth } from 'next-auth/middleware';

const publicEndpoints = ['/auth/signin', '/auth/signout', '/api/system'];

const nextAuth = withAuth({
pages: {
signIn: '/auth/signin',
},
});

export async function middleware(req: NextRequest, res: NextResponse) {
if (publicEndpoints.includes(req.nextUrl.pathname)) {
return;
}

return nextAuth(req as any, res as any);
}
import { type NextRequest, NextResponse } from 'next/server';
import { withAuth } from 'next-auth/middleware';

const publicEndpoints = ['/auth/signin', '/auth/signout', '/api/system'];

const nextAuth = withAuth({
pages: {
signIn: '/auth/signin',
},
});

export async function middleware(req: NextRequest, res: NextResponse) {
if (publicEndpoints.includes(req.nextUrl.pathname)) {
return;
}

return nextAuth(req as any, res as any);
}
Really weird this isnt out the box hehe
Want results from more Discord servers?
Add your server