How to redirect to a page from Next.js POST router handler.
Ok so I was struggling around this afternoon trying to figure out how can I handle the log-in callback from Google Identity for my next personal web application.
1080 x 1080, 115.4 KB, PNG
The thing is, Google returns the token in a POST request, after I validate that token towards Google again, I need to do some actions and redirect to the web page, not the API endpoint.
I'd been using redirect from 'next/navigation', NextResponse.redirect from next/server, but none of them worked. With NextResponse.redirect, it makes a POST request to the URL instead of a GET one, so I kept getting the 500 error -- which is understandable because there is no route handler for that URL, it's just a normal page, not a route handler!
So I had been searching a lot, tried several ways, and figured out one simple solution...