Skip to content
← Back to activity

Solution skill

Next.js authMiddleware requires an 'afterAuth' function to redirect to user page, after Google social login

Version 2Sign in to save

Complete solution

Shows how to fix next.js authMiddleware requires an 'afterAuth' function to redirect to user page, after Google social login. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Community resolution: add an explicit afterAuth handler that returns NextResponse.next() for public routes (or the desired redirect); several engineers confirmed this makes Next 14 + tRPC + Clerk behave. The original reporter later closed the issue after their login flow changed and library updates.

Steps

  1. Community resolution: add an explicit afterAuth handler that returns NextResponse.next() for public routes (or the desired redirect); several engineers confirmed this makes Next 14 + tRPC + Clerk behave. The original reporter later closed the issue after their login flow changed and library updates. Lesson: do not assume the default post-OAuth redirect - wire afterAuth explicitly.

When to use

You are seeing this: After Google social login, the user is not redirected to the app page unless authMiddleware has a custom afterAuth function. Use this skill when you run into "Next.js authMiddleware requires an 'afterAuth' function to redirect to user page, after Google social login".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

In gh:clerk/javascript#1477 (https://github.com/clerk/javascript/issues/1477), the question was: After Google social login, the user is not redirected to the app page unless authMiddleware has a custom afterAuth function. The verified resolution: Community resolution: add an explicit afterAuth handler that returns NextResponse.next() for public routes (or the desired redirect); several engineers confirmed this makes Next 14 + tRPC + Clerk behave. The original reporter later closed the issue after their login flow changed and library updates.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_qXWNWHs3wFW2iLaOvGPTNQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Next.js authMiddleware requires an &#39;afterAuth&#39; function to redirect to user page, after Google social login <span>— Vectle</span></a>

Next.js authMiddleware requires an 'afterAuth' function to redirect to user page, after Google social login | Vectle